[問題] 指標指向字串時,判斷大小寫?
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
dev-c
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
已判斷字母的ascii code值符合小寫,但count_min值不會加1?
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
小寫字數錯誤
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <stdio.h>
#include <stdlib.h>
int main(void){
char *ptr = "We Are Bast Friends.";
char ch;
int i=0;
int count=0;
int count_min=0;
while((*(ptr+i))!= '\0'){
if(97<*(ptr+i)<122){
count_min++;
}
count++;
i++;
}
printf("一共有%d個字元\n",count);
printf("一共有%d個小寫字元\n",count_min);
system("pause");
return 0;
}
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.46.112.3
→
08/16 22:48, , 1F
08/16 22:48, 1F
推
08/16 22:49, , 2F
08/16 22:49, 2F
→
08/16 22:56, , 3F
08/16 22:56, 3F
→
08/16 22:57, , 4F
08/16 22:57, 4F
→
08/16 22:57, , 5F
08/16 22:57, 5F
→
08/16 22:58, , 6F
08/16 22:58, 6F
→
08/16 23:10, , 7F
08/16 23:10, 7F
推
08/16 23:41, , 8F
08/16 23:41, 8F
→
08/17 00:01, , 9F
08/17 00:01, 9F
→
08/17 00:16, , 10F
08/17 00:16, 10F
→
08/18 02:11, , 11F
08/18 02:11, 11F
→
08/18 18:51, , 12F
08/18 18:51, 12F
→
08/22 04:58, , 13F
08/22 04:58, 13F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章