gpt4 book ai didi

c - 为什么我在 C 中收到参数初始化错误?

转载 作者:太空宇宙 更新时间:2023-11-04 00:39:56 25 4
gpt4 key购买 nike

struct subscriber

{

char phonenumber[20];

char name[50];

float amount;

}s;

void modifyrecords()

FILE *f;

char phonenumber[20];

long int size=sizeof(s);

if((f=fopen("c:/file.ojs","rb+"))==NULL)

exit(0);

system("cls");

printf("Enter phone number of the subscriber to modify:");

scanf("%[^\n]",phonenumber);

fflush(stdin);

while(fread(&s,sizeof(s),1,f)==1)

{

if(strcmp(s.phonenumber,phonenumber)==0)

{

system("cls");

printf("\n Enter phone number:");

scanf("%s",&s.phonenumber);

printf("\n Enter name: ");

fflush(stdin);

scanf("%[^\n]",&s.name);

printf("\n Enter amount: ");

scanf("%f",&s.amount);

fseek(f,-size,SEEK_CUR);

fwrite(&s,sizeof(s),1,f);

break;

}

}

fclose(f);

}

C:\Users***\Desktop\a.c|394|错误:参数“大小”已初始化|我在这段代码中收到参数 'size' is initialized 错误。谷歌搜索后我发现我可能必须传递某些参数来抑制此类错误。这是唯一的解决方案吗?实际上我使用的是 Code::Blocks 所以如果这是我如何在其中传递命令行参数的唯一方法?

最佳答案

这里有一个简单的语法错误:

void modifyrecords()

应该是:

void modifyrecords() {

另外,这个:

scanf("%s",&s.phonenumber);

应该是

scanf("%s",s.phonenumber);

这也适用于 s.name

关于c - 为什么我在 C 中收到参数初始化错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13210445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com