Hallo
I am programming with c language in Linux.
anyway i have to define a function that takes a binary file or a pointer of it and change the file by that, that it romoves line number X from it.
that is my function:
//(every 6 charechters are one line)
//filesize is the size of the file
Does your number of characters per line include the new line character? and why use fseek in your loop? fread will move the file pointer to the next read position for you..
thanks for replying man
the number of characters per line does not include the new line character.
i am using fseek because i dont want to read the line number (X-1) i could also define a counter that after every round in the loop it increments in 1, and when it is equal to X-1 i dont read from the file.
Reading the line is not a problem, writing it back is what you want to avoid. I'd rewrite your loop as follows,
1 2 3 4 5 6 7 8 9 10 11 12 13
...
unsignedchar hex[7] = {0}; // +1 for the new line character
// (assuming you are only handling linux text files)
while (!feof(fp))
{
size_t n = fread(hex, 1, 7, fp);
if(i!=(X-1))
{
fwrite(hex, 1, n, fp1);
}
i++
}
You should also close your files when you are done using them,
http://www.cplusplus.com/reference/clibrary/cstdio/fclose/
.. and if C isn't some silly requirement, have a look at using C++ fstreams instead,
http://www.cplusplus.com/reference/iostream/fstream/