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

时间:2021-02-27 22:44:52
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|error: parameter 'size' is initialized| I am getting parameter 'size' is initialized error in this code. After googling I found out I may have to pass certain arguments to suppress these kind of errors. Is this the only solution? Actually I am using Code::Blocks so if is the only way how do I pass command line arguments in it?

C:\桌面用户* * * \ \。b| 394|错误:参数“size”被初始化|,我得到参数“size”是在这个代码中初始化错误。在谷歌搜索之后,我发现我可能需要通过某些参数来抑制这些错误。这是唯一的解决办法吗?实际上,我正在使用代码::块,所以如果是唯一的方法,我如何通过命令行参数?

1 个解决方案

#1


6  

You have a simple syntax error here:

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

void modifyrecords()

should be:

应该是:

void modifyrecords() {

Also, this:

另外,这个:

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

should be

应该是

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

And that applies to s.name as well.

这也适用于s。

#1


6  

You have a simple syntax error here:

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

void modifyrecords()

should be:

应该是:

void modifyrecords() {

Also, this:

另外,这个:

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

should be

应该是

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

And that applies to s.name as well.

这也适用于s。