I am currently trying to read in an input file of 15,000 integers and pass these values into an array. I'm really rusty when it comes to passing command line arguments into the program, so perhaps I am not doing this the correct way. Here is what I have coded thus far:
#include <stdio.h>
int main(int argc, char *argv[]) {
int i;
FILE *fp;
int c;
int values[15000];
char line[32];
int index = 0;
for (i = 1; i < argc; i++) {
fp = fopen(argv[i], "r");
if (fp == NULL) {
printf(stderr, "cat: can't open %s\n", argv[i]);
continue;
}
while (fgets(line, sizeof(line), fp) != NULL) {
scanf(line, "%d", values[index];
index++;
}
fclose(fp);
}
return 0;
}
I am invoking gcc -o prob_5 input.txt from the command line and am receiving this error message:
/usr/bin/ld:input.txt: file format not recognized; treating as linker script
/usr/bin/ld:input.txt: syntax error
collect2: ld returned 1 exit status
Is there an error with my code or the command line arguments, or both?