By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,843 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

input and output file (txt file)

P: 16
Hi...
I've been trying to make a program where the input is txt file, and the output will be saved in txt file. But, I keep getting error Message.
My code looks like this:
Expand|Select|Wrap|Line Numbers
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. int main (){
  5.     int i,j;
  6.     float H [100][100];
  7.  
  8. FILE*in;
  9. in=fopen("0.txt","rt");
  10. FILE*out;
  11. out=fopen("rotation0.txt","w");
  12. if(in){
  13.   for(i=0;i<100;i++)
  14.     for(j=0;j<100;j++)
  15.       fscanf(in, "%f", &H[i][j]);
  16.   for(i=0;i<100;i++){
  17.     for(j=0;j<100;j++)
  18.       //printf("%d "H[i][j]);
  19.       printf("");;
  20.     }
  21.   }
  22. else {
  23. fprintf(stderr,"Cannot open file\n");
  24. return 1;
  25. }
  26.  for(i=0;i<100;i++){
  27.    for(j=0;j<100;j++){
  28.      printf("[%d][%d]=%f\n ",i,j,H[i][j]);
  29.      fprintf(out,"[%d][%d]=%f\n ",i,j,H[i][j]);
  30.    }
  31.  }
  32.  
  33. return 0;
  34. fclose(in);
  35. fclose (out);
  36. }
  37.  
The error message says:
"parse error before *"
" "out" undeclared"

I found a couple strange things; if I move FILE*in (line 8&9) below FILE*out (line 10&11), the error became:" "in" undeclared".
And if I use different compiler (I'm using cygwin currently), it works. unfortunately, I can't use the other compiler because it doesn't work if I increase the size of array.

Could you help me, please?

Thank you
Jun 7 '09 #1
Share this Question
Share on Google+
1 Reply


Expert 10K+
P: 11,448
Swap lines #9 and #10; in C first define your variables, then use them in statements etc.

kind regards,

Jos
Jun 7 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.