I am having a requirement to read a file line by line through a c program.
I know I can do it very straight by using a FILE pointer and using fgets
(if by fixed length string) or fgetc
(if by character by character). The only point here to note is that the length of a line in the file can be different. So , if i am using
char *fgets(char *__restrict s, int n, FILE *__restrict stream);
I do not know the value of "int n" here since it can vary from line to line in the file.
I searched for an answer for this query but i got to know the usage of getline
function which is c++ function. The only way for me is to read each character until i encounter a '\n' and get that copied to a string.
Is there any other way to do this straight in a c program ?