I was going to answer, and then I read the question. Unless you have a really big CSV file and you should really avoid that , there won't be an advantage to using seek over the easier method of reading the entire file into memory and writing it all back out when you're done.
Add a comment. Active Oldest Votes. Jonathan Leffler Jonathan Leffler k gold badges silver badges bronze badges.
Steve Emmerson Steve Emmerson 7, 5 5 gold badges 32 32 silver badges 58 58 bronze badges. You have to read as well as seek - or, more usually, you read until you find, then rewind with fseek to the start of the record so you can overwrite it.
If you only read part of the record, you might need to do seeks between the reads. However, the disk drive will probably be read in chunks that are bytes long some power of 2 between bytes and about 16 KiB and unless your record is extraordinarily long, you will merely be shuffling data around in your program by reading less than the full record; the actual disk traffic won't be affected by partial record reads.
Would it be possible for someone to write up an example of how to do this? Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.
Email Required, but never shown. The fseek is used to change the file pointer to the specified stream. The getc the function returns the character read as an unsigned char cast to an int otherwise EOF on error. Here are some errors listed 1. EBADF 3. EFBIG 4. EINTR 5. EIO 7. ENXIO 9. Rewind function is used to move file pointer position to the beginning of a file. The fseek in C with programming examples for beginners and professionals covering concepts, control statements, c array, c pointers, c structures, c union, c strings and more.
The following example demonstrates fseek Usage of functions. Let's compile and run the above program , This will create a file file. Initially, the program creates files and writes This is cdmana.
Submitted by Souvik Saha , on January 24, This also means that if EOF is reached that the partial block is dropped, not returned. I want you to show me the codes to display the bellow output form of rectangle using stars in c file :.
I come from a background in the Pick OS where we do a READ and get the whole item which is delineated by attribute marks char , value marks char and sub-value marks char Just curious. Marshall, I have no idea how the Pick system is implemented. I worked at Pick Systems for years as a tech support person.
I often worked with the programmers but never actually asked how the system was implemented. If I am wrong, please correct me. I want to increment the content of one file by one whenever that file opens, I.
Save my name, email, and website in this browser for the next time I comment. Notify me of followup comments via e-mail. Previous post: wget vs curl: How to Download Files Using wget and curl. All rights reserved Terms of Service. As with any OS, file handling is a core concept in Linux.
The stream is positioned at the beginning of the file. The file is created if it does not exist, otherwise it is truncated. The file is created if it does not exist. The stream is positioned at the end of the file. The initial file position for reading is at the beginning of the file, but output is always appended to the end of the file.
0コメント