我正在和一个比我更了解的朋友一起编写一些 C++ 代码,并且代码有一个错误,我想帮助解决这个问题,因为我不知道如何......
编辑
编译器在第 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);
}