mingke 31 Newbie Poster

Ah, I see it more clearly now...

Thank you for the explanation..

mingke 31 Newbie Poster

@salem: thanks for answering my question. It works now. But can I ask you, why did you say that, I'm not going to close files with this:
> return 0;
> fclose(in);
> fclose (out);

Honestly, I didn't get it. I suppose to write this in the end of codes,right?

@tux4life: thank you for your explanation.

mingke 31 Newbie Poster

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:

#include <stdlib.h>
#include <stdio.h>

int main (){
    int i,j;
    float H [100][100];

FILE*in;
in=fopen("0.txt","rt");
FILE*out;
out=fopen("rotation0.txt","w");
if(in){
  for(i=0;i<100;i++)
    for(j=0;j<100;j++)
      fscanf(in, "%f", &H[i][j]);
  for(i=0;i<100;i++){
    for(j=0;j<100;j++)
      //printf("%d "H[i][j]);
      printf("");;
    }
  }
else {
fprintf(stderr,"Cannot open file\n");
return 1;
}
 for(i=0;i<100;i++){
   for(j=0;j<100;j++){
     printf("[%d][%d]=%f\n ",i,j,H[i][j]);
     fprintf(out,"[%d][%d]=%f\n ",i,j,H[i][j]);
   }
 }

return 0;
fclose(in);
fclose (out);
}

The message says:
"parse error before *"
" "out" undeclared"

I found a couple strange things; if I move FILE*in below FILE*out, 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 increase the size of array.

Could you tell me, what's wrong with my code?

Thank you

mingke 31 Newbie Poster

I have four arrays as input, then used it in a function that result an output. Then I sorted the output array. Next step, I want to find the index and the value of the input array that resulted the sorted array. I keep getting the wrong result.
Here my (part of) code (forgive me for my poor codes;

for (i=0; i<size2; i++){               
    for (l=0;l<point3[i];l++){  
       for (a=0;a<b[i][l];a++){
            gradient [i][l][a]=(S[i][l][a]-Cy[i][l])/(R[i][l][a]-Cx[i][l]);
       }
     //To sort the output
       for (a=0;a<b[i][l]-1;a++){
          for (d=a+1;d<b[i][l];d++){  
            if (gradient[i][l][a]>=gradient[i][l][d]){
                  temp=gradient[i][l][a];                        
                   gradient[i][l][a]=gradient[i][l][d];
                    gradient[i][l][d]=temp;                    
              }
           } 
         }
      }
 
// To search the "R and S' index and value"
 for (i=0; i<size2; i++){               
    for (l=0;l<point3[i];l++){  
       for (a=0;a<b[i][l];a++){
            for (k=0;k<b[i][j];k++){        
                if (fabs((S[i][l][a]-Cy[i][l])/(R[i][l][a]-Cx[i][l]))==gradient[i][l][a]){
                   printf ("[%d][%d][%d]\t%f\t%f\n",i,l,k,R[i][l][k],S[i][l][k]);                   
                }                   
            }
         }
     } 
 }

The result I have is just R[1][1][3] and S[1][1][3];even though size2=4 and point3 is between 4 or 5. Why I keep getting this result? Is my loop incorrect or is it my if condition?
How can I fix it?
Thanks.

Salem commented: post == 1 && tags == true, well done! +31