鱼C论坛

 找回密码
 立即注册
查看: 2561|回复: 1

作业bug不会改求助

[复制链接]
发表于 2019-5-28 11:32:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
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[22];
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]='/0';
   printf( "%s/n ", name);
   name = guy + strlen(needle);
    /* Get next token: */
   guy = strstr( name, needle);
}
   return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2019-5-28 15:30:45 | 显示全部楼层
bug贴出来啊
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-3 19:23

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表