请教大家关于“字符串赋值”的问题,多谢!
我想让程序在某一条件下输出“miss”,在另外的条件下输出“hit”。我的程序如下,我总觉得这样做很笨拙,但是想不到其他好的办法。请大家多指点,多谢!
#include "stdio.h "
main()
{
char a[5] = "miss ";
char b[5] = "hit ";
int i;
printf( "please input a number: \n ");
scanf( "%d ",&i);
if(i <=5)
printf( "%s ",strcpy(b,a));
else
printf( "%s ",strcpy(a,b));
}
[解决办法]
if(i <=5)
printf( "%s ",b);
else
printf( "%s ",a);
[解决办法]
#include "stdio.h "
void main()
{
char a[5] = "miss ";
char b[5] = "hit ";
int i;
printf( "please input a number: \n ");
scanf( "%d ",&i);
i <=5 ? printf( "%s\n ",b):printf( "%s\n ",a);
}