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 位数字来区分是否有折扣码的用户。cat2 如果数字大于 0 所以,如果数字是 0,用户有折扣,所以他们没有折扣示例我有 cat0 bee1 ear2 eye0 当我打印 notdiscount : cat0 , eye0 折扣: bee1 , ear2
我通过 isdigit 检查数字,我在通过 strcpy 复制用户名时遇到问题。感谢帮助 。:]