Re: [问题] 如何得知一串数字由几个数字组成

楼主: pilimtv (pilimtv)   2014-06-21 07:19:55
//数字范围可超过200位
//只接受数字和ENTER键
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
int main( void )
{
int ASCII;
int Count = 0;
char *a = (char *) malloc ((Count + 1) * sizeof(char));
printf("请输入数字:");
while ( !_kbhit() ) {
ASCII = _getch();
if ( ASCII == 0xD )
break;
else {
if ( ASCII >= 48 && ASCII <= 57 ) {
printf("%c", ASCII);
a = (char *) realloc (a, (Count + 1) * sizeof(char));
a[Count] = (char) ASCII;
Count++;
if (Count == 1 && ASCII == 48)
break;
}
}
}
printf("\n有%d个数字为: ", Count);
while (Count
作者: GoodmanYY (GOgoHigher)   2014-06-22 15:46:00
已测试OK,我来仔细研究一下,谢谢您^^

Links booklink

Contact Us: admin [ a t ] ucptt.com