How to use files like arrays in c OR, how to properly handle files in c ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to use files like arrays in c OR, how to properly handle files in c ?

Unlike array, if we compare a character in a file with a char variable,(using fgetc) it also increments the pointer position. How to compare, like an array , without incrementing the position ? Also, How to know the value of a position in the file like we could use *arrayname[position] for an array ? solutions I don't want to use and reasons : Copy the file into an array - uses more memory. Decrement 1 position everytime after incrementing with fgetc - less efficient.

17th Mar 2021, 5:06 PM
Thnr
3 Answers
+ 1
Coder Kitten Thanks. Is there any function which returns a character, like fgetc, but doesn't change the pointer ?
18th Mar 2021, 10:36 AM
Thnr
+ 1
Coder Kitten So , are comparisons and other operations done by reading them first into memory ? I am actually trying to make a program which works like this : "grep -o 'characters[[:alnum:]]*' filename" on linux
18th Mar 2021, 11:02 AM
Thnr
+ 1
Thank you !
18th Mar 2021, 11:16 AM
Thnr