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