【发布时间】:2013-09-26 07:42:31
【问题描述】:
char input[32];
char name[32];
char discountUser[32];//not sure to using about arrays.
char notDiscountUser[32];//not sure to using about arrays.
int i,j;
int len;
fgets(input,32,stdin);
sscanf(input,"%s",name);
len = strlen(name);
for(i=0,j=0; i < len; i++)
{
if(isdigit(name[i]))
{
digits[j] = name[i];
if (digits[j] > 48)
{
strcpy(discountUser[i],name); //i want to stored the name at i index
printf("you have discount code\n");
}
else if (digits[j] <= 48)
{
strcpy(notDiscountUser[i],name); //i want to stored the name at i index
printf("you don't have discount code\n");
}
j++ ;
}
}
我需要区分是否有折扣码的用户 通过输入 3charofname 和 1 位数字,例如。猫2 如果数字大于0,则用户有折扣 如果 digit 是 0 所以,他们没有折扣 例如我有 cat0 bee1 ear2 eye0 当我打印 不打折 : cat0 , eye0 折扣 : bee1 , ear2
我通过 isdigit 检查数字,我在通过 strcpy 复制用户名时遇到问题。 感谢帮助 。 :]
【问题讨论】:
-
strcpy前需要加**什么?
-
BTW char input[32] 是一个数组,char discountUser[32][32] 是一个矩阵。所以 32 列 32 行
-
什么是数字[j]?我认为您还需要阅读 strcpy 的工作原理:cplusplus.com/reference/cstring/strcpy