|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
>"D:\gcc\bin/g++" -Os -mconsole -Wall -Wshadow -fno-common -static-libgcc -static-libstdc++ -std=gnu++11 -fpermissive "26.c" -o "26.exe"
26.c: In function 'void spilt(char*)':
26.c:35:22: warning: declaration of 'name' shadows a global declaration [-Wshadow]
void spilt(char *name)
^
26.c:7:6: warning: shadowed declaration is here [-Wshadow]
char name[30];
这俩warning啥意思???有影响么
还有为啥我输入stark,Tony没问题,输入America,Captain还是出现tony Stark??
^
>Exit code: 0
#include <stdio.h>
#include <string.h>
char guy1[]="50:Tony Stark";
char guy2[]="20:Peter Benjamin Parker";
char guy3[]="1500:Thor";
char guy4[]="99:Captain America";
char name[30];
void spilt(char *);
void input();
void check();
int main()
{
input();
check();
printf("/n");
}
// 1. user input the name function
void input(){
int i =0;
printf("Type in a file name: names.txt\n");
printf("Enter the name of a person: ");
scanf("%s", name);
for (i=0;i<30;i++){
if(name[i]==44){//ASCII , = 44 spilt the name if type: Secondname ,Firstname
spilt(name);
//printf("S,F success");
}
}
}
/* 2. spilt the name*/
void spilt(char *name)
{
int count = 0;
while((name[count] = getchar()) != ',' && name[count] != '\n')
++count;
name[count] = '\0';
}
/*3. check the input name right or not.*/
void check(){
if((strstr(guy1, name))!= NULL ){
printf("Tony Stark is not a pensioner.\n");
}
else if((strstr(guy2, name))!= NULL){
printf("Peter Benjamin Parker is not a pensioner.\n");
}
else if((strstr(guy3, name))!= NULL){
printf("Thor is a pensioner.\n");
}
else if((strstr(guy4, name))!= NULL){
printf("Captain America is a pensioner.\n");
}else{
printf(" No record of this person.");
}
}
本帖最后由 bin554385863 于 2019-5-30 14:36 编辑
chlm007 发表于 2019-5-30 14:22
谢谢啦。所以是什么不用改喽?另外strstr()我用的对么?
strstr(guy1, name))!= NULL
如果为真,则表示name就是guy1的子串,返回name在guy1中首次出现的地址。
如果为假,则表示name不是guy1的子串。
|
|