❶ c語言中如何判斷字元長度
使用string庫函數里的strlen函數即可判斷字元長度。
strlen函數可以計算給定字元串的長度,返回值為長度值。
例如計算字元串「helloworld2017」的長度的代碼:
#include<stdio.h>
#include<string.h>
intmain()
{
inti;
i=strlen("helloworld2017");
printf("%d",i);
}
運行結果如下:
❷ C語言問題輸入幾個字元,怎麼判斷輸入的是幾個字元
一般都要約定一個結束標記的
比如 以換行作為結束
或者以#作為結束
或者 以EOF作為結束等等
如果不約定結束 那麼是沒辦法知道是否輸入完畢的。
❸ 如何用c語言判斷一串字元中有幾個是數字幾個是字母
#include<stdio.h>
externintsystem(constchar*);
intmain()
{
voidsqu(char*str,int*p1,int*p2);
intmatchNum(char*s);
intmatchLetter(char*s);
inta=0,b=0;
charinput[50];
printf("Pleaseinputastring... ");
gets(input);
squ(input,&a,&b);
printf("Thereare%dnumber(s)and%dletter(s)above. ",a,b);
system("pause");
return0;
}
voidsqu(char*str,int*p1,int*p2)
{
for(;;){
if(*str=='