我被要求为我的大学课程制作程序,它需要检查文件中有多少个开放和封闭的括号。我正在为我的函数的两个错误信息:无法转换文件* -C++
40:22:不能转换FILE * {aka_IO_FILE *}以 '为const char *' 的说法 '1' FILE *
fpin =的fopen(fpin);
42:22:警告格式'%s'需要类型'char *'的参数,但参数2的类型为'int'
printf(“Could not open%s \ n”,arr [1]);
void countBrackets(char arr[])
{
int bracketCount = 0:
int lineNumber = 0;
//tracking position in file
FILE* fpin;
//open file and check to make sure
//file opened safley
fpin = fopen(fpin);
if (fpin == NULL){
printf("Could not open %s \n", arr[1]);
return;
}
//Count how many opened and closed { and } brackets are
//in the file
for (char currCh = 0; currCh > lineNumber; currCh ++){
if (currCh == '{') {
bracketCount ++;
}else if (currCh == '}') {
bracketCount ++;
}else (currCh == '\n') {
lineNumber ++;
}
//display error messages for the user
if (bracketCount < 0) {
printf("there is more closing brackets than opening\n");
}else{
printf("There is more opening brackets than closing\n");
}
}
fclose(fpin);
}
阅读'的fopen()'库函数的说明。它的第一个参数必须是一个'const char *'。由于'arr'是一个数组,'arr [1]'是一个'char','%s'格式规范需要'const char *'值。 –