Filesystems 文件指针位置

Filesystems 文件指针位置,filesystems,Filesystems,这样行吗?我的文件指针会在XYZ()中出错吗 如果打开文件的附加句柄,则不影响以前的句柄。就像在记事本上打开文件两次一样,在第一个实例中将光标移动到一个部分,但在另一个实例中光标不会移动 (坏例子,我知道…这是一个坏形式,尽管它在技术上可能是正确的。 更好的办法是 function XYZ() { handle = fopen(myFile) // some processing // I am in the middle of the file Call ABC

这样行吗?我的文件指针会在XYZ()中出错吗


如果打开文件的附加句柄,则不影响以前的句柄。就像在记事本上打开文件两次一样,在第一个实例中将光标移动到一个部分,但在另一个实例中光标不会移动


(坏例子,我知道…

这是一个坏形式,尽管它在技术上可能是正确的。 更好的办法是

function XYZ()
{
    handle = fopen(myFile)
    // some processing
    // I am in the middle of the file
    Call ABC(handle) 
    fclose(handle)  
}

ABC (handle)
{
    //do some processing on handle
}
如果你的语言支持,我强烈建议你使用它 即:

function XYZ()
{
    handle = fopen(myFile)
    // some processing
    // I am in the middle of the file
    Call ABC(handle) 
    fclose(handle)  
}

ABC (handle)
{
    //do some processing on handle
}
function XYZ()
{
    handle = fopen(myFile)
    try 
    {
       // some processing
       // I am in the middle of the file
       Call ABC(handle) 
    }
    finally
    {
       fclose(handle)  
    }
}

ABC (FilePtr handle)
{
    //do some processing on handle
}