作业bug不会改求助
c语言写一个程序,给了4个人年龄名字,输入一个名字得出回复。例子:
Type in a file name: names.txt
Enter the name of a person: Mary Jane Doe
Mary Jane Doe is not a pensioner.
要求:不用strtok函数,但要写一个函数把字符串分解。
#include <stdio.h>
#include <string.h>
char guy1[]="29:Bloggs,Joe";
char guy2[]="54:Doe,Mary Jane";
char guy3[]="12:Williams Green,Hannah";
char guy4[]="67:Little-Biggs,Clive";
char fullname;
char spilt();
int main()
{
fullname = spilt(fullname);
printf("Type in a file name: names.txt\n");
printf("Enter the name of a person: ");
scanf("%c",fullname);//find zhe people
if((strstr(guy1, fullname))!= NULL ||(strstr(guy2, fullname))!= NULL ||(strstr(guy3, fullname))!= NULL )
{
printf("\n%s is not a pensioner.\n", fullname);
}
else if ((strstr(guy4, fullname))!= NULL )
{
printf("\n%s is a pensioner.\n", fullname);
}else{printf(" No record of this person.");}
return 0;
}
char spilt() //spilt the name
{
char *name=fullname;
const char *needle=",";
char *guy = strstr( name, needle);
while( guy != NULL )
{
guy='/0';
printf( "%s/n ", name);
name = guy + strlen(needle);
/* Get next token: */
guy = strstr( name, needle);
}
return 0;
} bug贴出来啊
页:
[1]