Hi guys i have done the following code and basically im trying to read a file and put line numbers to every line in the file. How would i read it in line by line then putting line numbers next to it. I have to use an Int for the lineNo's and int input_char variables i cant change them so im having difficulty finding a correct function to read them line by line which takes an int and not a char.
Code:#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { int line_no = 1; int input_char; FILE *fp; if(argc !=2) /* check for 2 arguments*/ { fprintf(stderr, "invalid usage :%s\n", argv[0]); return 1; /* stop processing if failes */ } if((fp = fopen(argv[1], "r")) == NULL) /* opens file for reading and checks if it exists */ { fprintf(stderr, "invalid usage: %s\n", argv[0]); return 1; /* stop processing if fails*/ } printf("dude\n"); while(fgetc(fp)!=NULL) { fprintf(fp, "%s", input_char); line_no++; } fclose(fp); return EXIT_SUCCESS; }



LinkBack URL
About LinkBacks


