thanks Robert
it is really the file opeing and referencing in the scanf. your code
looks ok, but I need the file open and just get confused with the
arguments in
FILE *stream, *fopen();
and
stream = fopen("myfile.dat","r");
Here is a version that will open the files provided on the commandline
one at a time and process them:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
int main (int argc, char *argv[]) {
double d;
int i, j;
FILE *fp;
if (argc < 2) {
fprintf(stderr, "No filename provided\n");
return EXIT_FAILURE;
}
for (j = 1; j < argc; j++) {
errno = 0;
fp = fopen(argv[j], "r");
if (!fp) {
fprintf(stderr, "Could not open %s: %s\n", argv[j], errno ?
strerror(errno) : "Unknown reason");
continue;
}
while ((i = fscanf(fp, "%lf", &d)) != EOF)
if (i == 1)
printf("Read %f\n", d);
else
fscanf(fp, "%*s"),puts("Bad input");
}
return 0;
}
It's pretty straight-forward but if you have any questions feel free to
ask. As far as getting confused about function prototypes, etc., did
your implementation come with any documentation? If not then it might
serve you well to pick up a good reference on C programming, I
recommend "C: A Reference Manual" by Harbison and Steele.