how to movw to the next line
Hello all,
M new to coding.. n i have this task wherein i m suppose to write a code to print every field in a file with a printf statement .here i swhat i have done so far. my problem is that i m not able to figure out how to move to the next line. please help me with this.#include <stdio.h> //#define EOF 0 int main() { // open the text file "fred.txt" for writing // close the stream, so all changes to the file are saved // open the file "fred.txt" for reading FILE *in = fopen("kerg3470.03o", "rt"); // read the first line from the file char buffer[100]; fgets(buffer, 20, in); //display what we've just read printf("The rinex version of:\"hanu.c\": %s\n", buffer); fgets( buffer, 23 , in); printf("The type of:\"hanu.c\": %s\n", buffer); fgets( buffer, 40 , in); printf("The type of:\"kerg3470.03o\": %s\n", buffer); while(in==EOF) fgets( buffer, 50, in); printf("The type of:\"kerg3470.03o\": %s\n", buffer); // close the stream fclose(in); return 0; } |
[QUOTE=madhuhan;4913622]Hello all,
M new to coding.. n i have this task wherein i m suppose to write a code to print every field in a file with a printf statement .here i swhat i have done so far. my problem is that i m not able to figure out how to move to the next line. please help me with this.#include <stdio.h> //#define EOF 0 int main() { // open the text file "hanu.c" for writing // close the stream, so all changes to the file are saved // open the file "fred.txt" for reading FILE *in = fopen("hanu.c", "rt"); // read the first line from the file char buffer[100]; fgets(buffer, 20, in); //display what we've just read printf("The rinex version of:\"hanu.c\": %s\n", buffer); fgets( buffer, 23 , in); printf("The type of:\"hanu.c\": %s\n", buffer); fgets( buffer, 40 , in); printf("The type of:\"hanu.c\": %s\n", buffer); while(in==EOF) fgets( buffer, 50, in); printf("The type of:\"hanu.c\": %s\n", buffer); // close the stream fclose(in); return 0; } |
You could see eg http://stackoverflow.com/questions/2...he-line-length : note the comments on the getline() fn.
Fundamentally you need a loop of eg fgets() or whatever input fn you use. Google has millions of results on this eg also read http://stackoverflow.com/questions/4...ne-using-fgetc |
thanks a ton ! now i have another problem.. could u pls help with as to how to skip reading lines in btw while using fscnf statements.. and print only selected data...
thanks in advance.... |
Mate, seriously just google it; there are more C tutorials on the web than you could throw a compiler at ;)
Incidentally, you might also ask the Mods (via the Report button) to move this to the Programming forum. Please always use code tags https://www.linuxquestions.org/quest...do=bbcode#code to post your code and use proper English, not 'could u pls help '. Thank you. |
how do i print specific data from a file
Hey there is a file...
223423 45435 hjhsdfkjhdskjclk aaaaaaaaaaaaa djdckjdxlclklk bbbbbbbbbbbbb djhsbxjhABN hhhhhhhhhhhhh 465346 989374839 9090 73982 879378 80980 sorry for the random data :P.. anyway i need to print only the first line ignore aaaaaa... and print the fourth line after the first one.. how do i skip those line and ignore aaaa... in the same line... looking forward for the replies... |
All times are GMT -5. The time now is 03:41 PM. |