我目前在该代码块中遇到标题错误。
void Option_3(char filename)
{ // profit for a month
FILE *ptr_file;
int num1, num2, num3;
int a[31],b[31],c[31];
int count=0;
int i;
ptr_file = fopen ( filename ,"r"); // error is here at file name
稍后主要
void main()
{
int select;
char filename;
select = 0 ;
filename = "April.txt"; //here the equals sign is giving me the error.
最佳答案
您需要将其声明为char *
:
void main()
{
int select;
char *filename; // Note the declaration
select = 0 ;
filename = "April.txt";
也在 Option_3
的参数声明中更改它:
void Option_3(char *filename)
原因是,将其声明为 char
意味着您有一个变量来保存 char
类型的对象。 C 中的字符序列是以 '\0'
结尾的字符数组,因此,char *
是正确的类型。
更新:更合适的是将其声明为 const char *
,因为您无法修改字符串文字。
关于c - 在c中,char类型的参数与const char参数类型不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23676223/