将光标移到行尾
我想向txt中写数据,但是每写一行,光标就跑到行首了,请问怎么将光标移到行尾?还有怎么换行 SetFilePtr (, 0, 2);用它试试! Moves the file pointer for the file specified by fileHandle to a location that is offset bytes from origin. Returns the offset of the new file pointer position from the beginning of the file.
You can use SetFilePtr to obtain the file size by setting offset to 0 and origin to 2. In this case, the return value indicates the file size, and the file pointer points to the end of the file.
You can position the file pointer beyond the end of the file. Intermediate bytes, bytes between the old end of file and the new end of file, contain values that might vary. An attempt to position the file pointer before the beginning of the file causes the function to return an error.
If the file is a device that does not support random access, such as the Standard Input, the function returns a value that might vary.
Example/* Open or create the file c:\TEST.DAT, move 10 bytes into the file, and write a string to the file. */
/* Note: In C, use \\ in pathname instead of \. */
int handle, result;
long position;
handle = OpenFile("c:\\TEST.DAT", 0, 2, 1);
if (handle == –1){
FmtOut("error opening file");
exit(1);
}
position = SetFilePtr(handle, 10L, 0);
if (position == 10){
result = WriteFile(handle, "Hello, World!", 13);
if (result == -1)
FmtOut("error writing to file");
}
else
FmtOut("error positioning file pointer");
CloseFile(handle);
file:///c:/program%20files/national%20instruments/cvi85/bin/libref/dot.gif Prototype file:///c:/program%20files/national%20instruments/cvi85/bin/libref/dot.gif
long SetFilePtr (int File_Handle, long Offset, int Origin); 谢谢楼上的,我用fprintf直接换行做出来了 3# cpubbs 换行可以直接在数据后面加\n就可以了!
页:
[1]