名和姓的调换,代码求修正
输入一英文名,名在前,姓在后,通过函数把姓放在前,名在后。初次写的,不会很会。求修正。
还有调试时: warning C4047: 'function' : 'const char *' differs in levels of indirection from 'const int '
: warning C4024: 'strcat' : different types for formal and actual parameter 2
#include <stdio.h>
#include <string.h>
void changename(char *Name,char *NewName)
{
char *p;
p = strchr(Name,' ');
p = "\0";
strcpy(NewName, p+1);
strcat(NewName,'.');
strcat(NewName,Name);
p = " ";
}
void Mean()
{
printf("1.Enter The Name!\n");
printf("2.End The system\n");
}
int chooser(int x)
{
char Name[100],NewName[100];
if(x = 2) return 0;
else if(x = 1)
{
gets(Name);
changename(Name,NewName);
puts(NewName);
printf("\n");
Mean();
printf("Choose to control!:");
scanf("%d",&x);
chooser(x);
}
else
{
printf("ERROR!!");
printf("Choose to control!:");
scanf("%d",&x);
chooser(x);
}
return 1;
}
void main(void)
{
int x;
Mean();
printf("Please Enter Number!:");
scanf("%d",&x);
chooser(x);
}
[解决办法]
p = "\0";
//楼主,这句话的意思不是赋值操作,而是让P指针指向了"\0"这个字符串常量