<分区>
我在函数调用点遇到段错误。请帮忙提供任何信息。我是编码的新手,所以非常感谢您提供任何帮助!段错误发生在“主要”功能中。
#include<stdio.h>
#include<stdlib.h>
#define MAX 100
void write();
void read();
int main()
{
int x;
while(x!=2)
{
printf("Type 0 to go to write program, type 1 to go to read program, type 2 to end program\n");
scanf("%d",x);
if(x==0)
write();
if(x==1)
read();
}
return 0;
}
void write()
{
FILE *finalptr;
char name[MAX],gift[MAX];
int none;
if((finalptr=fopen("names.dat","w"))==NULL)
{
printf("File could not be opened\n");
}
else
{
printf("Enter the gifter's name2gift.\n");
printf("Enter EOF to end input.\n");
printf("? ");
scanf("%s%d%s",name,none,gift);
while(!feof(stdin))
{
fprintf(finalptr,"%s %s\n",name,gift);
printf("? ");
scanf("%s%d%s",name,none,gift);
}
fclose(finalptr);
}
}