"bowlderster" <> ha scritto nel messaggio
news:...
[snip]
>int a[30] = {0};
You meant a[MAX]. If you change MAX at the beginning and forget to change 30
here, that could be a problem.
> if( (fp = fopen("test.txt", "r")) == NULL )
> printf("Open file fail!!!\n");
If I redirect the output to a file, I won't be able to read the error until
I read that file.
You must write to stderr, not stdin. If you use perror() it will also add a
colon, a space, an explaination of the error, and a newline char.
perror("Open file fail");
Also, if the test fails, the rest of the program will run as if fp wasn't
NULL.
use exit(EXIT_FAILURE); (you must #include <stdlib.h> for these), or even
just return EXIT_FAILURE as you are in main()
> But when I change the type of the array to double
> ...
> double a[30];
> ...
> fscanf(fp,"%g",&a[i]);
> printf(fp,"%g",a[i]);
> ...
>
> It cannot work. It seams that the array is zero.
http://c-faq.com/stdio/scanf2.html