[Error] cannot convert 'const char*' to 'FILE* {aka _iobuf*}' for argument '1' to 'int fscanf(FILE*, const char*, ...)'
时间: 2023-12-24 15:05:00 浏览: 612
这个错误的原因是你在使用 fscanf 函数时,第一个参数应该传入一个文件指针(FILE*),但是你传入了一个字符串常量(const char*)。请确保你传入的第一个参数是一个已经打开的文件指针。你可以在调用 fscanf 函数之前,使用 fopen 函数打开一个文件,并将返回的文件指针作为第一个参数传入 fscanf 函数中。例如:
```
FILE* fp;
fp = fopen("myfile.txt", "r");
if (fp == NULL) {
printf("Failed to open file\n");
return -1;
}
int num;
fscanf(fp, "%d", &num);
fclose(fp);
```
这段代码将打开名为 "myfile.txt" 的文件,并从文件中读取一个整数,并将其存储在 num 变量中,最后关闭文件指针 fp。
相关问题
[error] cannot convert 'int*' to 'const char*' for argument '1' to 'size_t strlen(const char*)'
这个错误是因为在调用strlen函数时,传入的参数类型是int*,而strlen函数的参数类型应该是const char*。因此,编译器无法将int*转换为const char*,导致出现了这个错误。
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![cpp](https://img-home.csdnimg.cn/images/20250102104920.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)