i need to write a program which opens a file in a function, not in main, and open it from dos command...
ive writen the program to open it in main but im not aloud to do that i have to make a seperate function for opening a file
my question is how do i go about passing the arguments to the function after declaring them in the main....Code:#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int main(int argc, char* argv[]) { FILE * in; int c; int num; int count = 0; in = fopen(argv[2],"r"); num = atoi(argv[1]); while((c = fgetc(in)) != EOF) { if(count < num) { fputc(c, stdout); count++; } else { fprintf(stdout,"\n"); count = 0; } } return 0; }
thanks guys



LinkBack URL
About LinkBacks


