我試圖做出三個簡單的c程序,但我只限於其中的一個,因爲這第一個問題只針對一個。 (是啊,這是硬件的情況下,你是好奇。)如何從C字符串中提取數字?
對於這個程序,我們的目標是創建一個可以採取的字符串:
"BCC 6 T LL 8 9 *** & [email protected]@@@@"
和輸出/打印
"689"
我將在下面粘貼的代碼是我對此的悲傷嘗試,實際上我沒有得到任何結果。任何幫助表示讚賞。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main()
{
printf("BCC 6 T LL 8 9 *** & [email protected]@@@@\n");
char ch=getchar();
while(ch!='\n')
{
if(isdigit(ch)|| ch!='*' || ch!='@')
printf("%c", ch);
}
return 0;
}
您是否期待'getchar()'在您打印的行中讀取?或者是用戶應該複製並粘貼輸出? – Barmar
我正在爲getchar()讀取行,但它本來可以是。 – Jormungandr
你不需要爲編碼新手道歉:這裏的每個人都在某處。 – dasblinkenlight