I have a project to have a file read using argc and argv. Then sort it and do some other things. I'm having trouble with the very first step. Loading the file. This is what I have so far. Any help you be great.
Do you mean this?
#include <stdio.h>
void openFile(int argc, char *argv[]);
int main(int argc, char *argv[])
{
openFile(argc, argv);
printf("\n\n");
getchar();
return 0;
}
void openFile(int argc, char *argv[])
{
FILE *hfile;
int i;
printf("\nThe number of arguments is %d", argc);
printf("\nThe name of the program is %s", argv[0]);
for ( i = 1; i < argc; i++)
{
printf("\nUser value No. %d: %s\n", i, argv[i]);
hfile = fopen(argv[i],"r");
if(!hfile){
printf("Error opening file %d!",i);
}else{
//do what you want with the file
}
}
}