(New page: '''print_file function''': Opens a file and prints it line by line ----------------------------------------------- int print_file(char * filename); int main(int argc, char * argv[]...) |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
[['''print_file function''']]: Opens a file and prints it line by line | [['''print_file function''']]: Opens a file and prints it line by line | ||
− | + | ||
int print_file(char * filename); | int print_file(char * filename); | ||
Line 37: | Line 37: | ||
return 0 ; | return 0 ; | ||
} | } | ||
+ | |||
+ | |||
+ | [[''''''(**the format is not at basic coding standards due to the "Rhea" text editor)'''''' | ||
+ | ]] |
Latest revision as of 16:42, 5 May 2011
'''print_file function''': Opens a file and prints it line by line
int print_file(char * filename);
int main(int argc, char * argv[]) {
if(argc < 2) { printf("Need File\n"); return -1; }
char * filename = argv[1];
return print_file(filename); }
int print_file(char * filename) { FILE *f; f = fopen(filename, "r");
if(f == NULL) return -1;
const int BUFFER_SIZE = 100; char buffer[BUFFER_SIZE];
while(fgets(buffer, BUFFER_SIZE,f) != 0 ) { printf("%s", buffer); }
fclose(f); return 0 ; }
[['(**the format is not at basic coding standards due to the "Rhea" text editor)'
]]