大家看看这个程序,怎么跳不出do..while循环
程序代码:
#include <stdio.h>
//#include <ctype.h>
#include <stdlib.h>
#define _STDC_WANT_LIB_EXT1_ 1
#define max_len 2
int main (void)
{
char xy[max_len] = {'0'};
int test = 0;
long int xx = 0;
printf("\nThis progarm is build a Mult-sheet.");
do
{
test = 0;
printf("\nPlase input a number for build the Mul-sheet : ");
fflush(stdin);
int ret_scan = scanf_s("%c", xy, sizeof(xy));
if(ret_scan == EOF)
{
printf("Error reading,enter overflow!!\n");
return 1;
}
for(int i = 0; i<max_len; ++i)
{
if(xy[i]<'0' || xy[i]>'9')
{
test = 1;
break;
//printf("xy[%d] = %c\n", i,xy[i]);
}
//printf("xy[%d] = %c\n", i,xy[i]);
}
}
while(test == 1);
//while(isalpha(xy) || isspace(xy));
xx = atol(xy);
//printf(" xx = %ld\n", xx);
for(int i = 1; i <= xx ; ++i)
{
for(int j = 1; j <= xx; ++j)
{
printf("\t%d", i*j);
}
printf("\n\n");
}
return 0;
}
我用test做测试标志,想通过for()循环检查char xy[]中每一个字符是否是数字。怎么do...while循环出不来了呢?而且我用scanf_s()函数规定最多输入两位字符,但是就是不起作用,为何?





