So, theres this program which works for C++, but im having problems when i try to convert it for C, below is the program with the changes that i made to try to make it work for C, and the way it was before is shown with ''//....". When i try to compile it i get the message "cannot convert 'const char*' to 'FILE*' for argument '1' to 'int fscanf(FILE*, const char*,...)' " at line 24, which is "fscanf("%d", &M[j][k]);" what should i do??
Code:#include <stdio.h> #include <stdlib.h> unsigned int N[6][3]= { 1, 0, 2, 1, 2, 0, 0, 1, 2, 0, 2, 1, 2, 1, 0, 2, 0, 1 }; int main(void) { unsigned int M[3][3], j=0, k=0, p=0, menor=~0, soma=0, i=0; FILE *arq; //fstream arq("garrafas.eco",ios::in); arq = fopen("garrafas.eco", "r"); while(!feof(arq))// while(!arq.eof()) { for(j=0; j<3; j++) for(k=0; k<3; k++) fscanf("%d", &M[j][k]); //arq >> M[j][k]; for(i=0; i<6; i++) { for(j=0; j<3; j++) for(k=0; k<3; k++) if(k!=N[i][j]) soma+=M[j][k]; if(soma<=menor) { menor=soma; p=i; } } for(j=0; j<3; j++) printf("%c", N[p][j]); //cout << "MVB"[N[p][j]]; printf("%d", menor); //cout << " " << menor << endl; } system("PAUSE"); return 0; }



LinkBack URL
About LinkBacks



