我正在與一位朋友比較瞭解一些C++代碼,該代碼有一個bug,我想幫助解決這個問題,因爲我無法弄清楚如何......(已解決)C++使用* lec = fopen()修復語法調試;
編輯 編譯器在第59行停止,其中:編寫了FILE *ecr("result.txt","wt");
。
還有很多其他的事情來解決,我定到49(59現在;))我再次受阻...
謝謝!
編輯(再次,抱歉) 隨着消息:
C:\Users\ad\Desktop\PYTHON\josh\josh\color\3d\solution_to_array.cpp||In function 'int main()':|
C:\Users\ad\Desktop\PYTHON\josh\josh\color\3d\solution_to_array.cpp|59|error: expression list treated as compound expression in initializer [-fpermissive]|
C:\Users\ad\Desktop\PYTHON\josh\josh\color\3d\solution_to_array.cpp|59|error: cannot convert 'const char*' to 'FILE* {aka _iobuf*}' in initialization|
C:\Users\ad\Desktop\PYTHON\josh\josh\color\3d\solution_to_array.cpp|82|error: expected initializer before '<' token|
C:\Users\ad\Desktop\PYTHON\josh\josh\color\3d\solution_to_array.cpp|82|error: expected ';' before '<' token|
C:\Users\ad\Desktop\PYTHON\josh\josh\color\3d\solution_to_array.cpp|82|error: expected primary-expression before '<' token|
C:\Users\ad\Desktop\PYTHON\josh\josh\color\3d\solution_to_array.cpp|84|error: expected ')' before ']' token|
C:\Users\ad\Desktop\PYTHON\josh\josh\color\3d\solution_to_array.cpp|84|error: expected ')' before ']' token|
C:\Users\ad\Desktop\PYTHON\josh\josh\color\3d\solution_to_array.cpp|84|error: expected primary-expression before ']' token|
C:\Users\ad\Desktop\PYTHON\josh\josh\color\3d\solution_to_array.cpp|84|error: expected ';' before ']' token|
||=== Build finished: 9 errors, 0 warnings (0 minutes, 0 seconds) ===|
如果有人能想出如何解決這個問題,這將是偉大的!
代碼:
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <stdio.h>
#include <string.h>
using namespace std;
int main() {
int COL = 0;
int LIN = 0;
cout << endl << "columns?" << endl;
cin >> COL;
cout << "lines?" << endl;
cin >> LIN;
int CELL = LIN*COL;
cout << CELL << " cells" << endl;
//1- reading the file priority.csv
char Coul[COL][LIN];
for (int i=0; i<COL; i++) Coul[i][0]='\0';
FILE *lec=fopen("priority.csv","rt");
if (lec == NULL) {
printf("Error");
return(0);
}
char ligne[120];
int N;
for (int i=0; i<COL; i++)
{
char nom[8];
fgets(ligne,15,lec);
sscanf(ligne,"%d,%s",&N,nom);
if (N == i) strcpy(Coul[i], nom);
else {printf("Error");
break;
}
}
fclose(lec);
//2- reading the file solution.txt and writing the result.
lec=fopen("solution.txt","rt"); // FIXED HERE
if (lec == NULL) {printf("Error");
return(0);
}
FILE *ecr=fopen("result.txt","wt"); //STOPS HERE
for (int i=1; i<CELL; i++)
{
char c[4][8]; // 4 color names
float v[4]; // 4 values
fgets(ligne,119,lec);
sscanf(ligne,"%d,%s,%f,%s,%f,%s,%f,%s,%f",
&N, c[0], &v[0], c[1], &v[1], c[2], &v[2], c[3], &v[3]);
if (N == i)
{
if (strlen(c[0]) == 0) // la ligne est vide
{
fprintf(ecr,"%d ",i);
for (int i=0; i<COL; i++) fprintf(ecr,"0 ");
fprintf(ecr,"\n");
}
else
{
fprintf(ecr,"%d ",i);
int r[4];
// we search the rang of c[ordre]
for (int ordre=0; ordre<4; ordre++)
{
for (int ir=0, ir<COL; ir++)
{
if (strcmp(c(ordre], Coul[ir]) == 0) r[ordre]=ir;
}
}
for (int ir=0; ir<r[0]; ir++) fprintf(ecr,"0 ");
fprintf(ecr,"%d ",v[0]);
for (int ir=r[0]+1; ir<r[1]; ir++) fprintf(ecr,"0 ");
fprintf(ecr,"%d ",v[1]);
for (int ir=r[1]+1; ir<r[2]; ir++) fprintf(ecr,"0 ");
fprintf(ecr,"%d ",v[2]);
for (int ir=r[2]+1; ir<r[3]; ir++) fprintf(ecr,"0 ");
fprintf(ecr,"%d ",v[3]);
for (int ir=r[3]+1; ir<57; ir++) fprintf(ecr,"0 ");
fprintf(ecr,"\n");
}
}
else {printf("Error"); break;}
}
fclose (ecr);
fclose(lec);
}
@ H2CO3哦,來吧,停止它......誰在乎變量是否有法國名稱?除此之外你可以閱讀它們,所以什麼??? –
@ bash.d ***即使我說法語,但是非常非常難讀,***(和其他人)都習慣於英語(如果一個人不知道變量名是什麼意思,那麼很難弄清楚代碼的含義......) – 2013-08-07 14:41:54
因此,如果你是一個編碼員/程序員/無論你應該能夠應付那個......你是一個聰明的人,是不是? –