亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    c語言統(tǒng)計字符串中各個字符的個數(shù)

    c語言統(tǒng)計字符串中各個字符的個數(shù)

    目標:

    輸入一行字符,統(tǒng)計其中各種字符的個數(shù)。

    具體代碼:

    #include<stdio.h> #include<stdlib.h> #include<string.h> #define M 1024 void main() { 	char str[M]; 	fgets(str, M, stdin); 	int space = 0; 	int letter = 0; 	int num = 0; 	int other = 0; 	for (int i = 0; i < (int)strlen(str); ++i) { 		if (str[i] == ' ') { 			space += 1; 		} 		else if (str[i] > 64 && str[i] < 91 || str[i]>96 && str[i] < 123)  { 			letter += 1; 		} 		else if (str[i] > 47 && str[i] < 58)  { 			num += 1; 		} 		else { 			if (str[i] != 'n') {//因為fgets()函數(shù)會在末尾自動加上n,影響判斷結(jié)果,需要判斷是否為換行符 				other += 1; 			} 		} 	} 	printf("空格的個數(shù)為:%dn", space); 	printf("英文字母的個數(shù)為:%dn", letter); 	printf("數(shù)字的個數(shù)為:%dn", num); 	printf("其他字符的個數(shù)為:%dn", other); 	system("pause"); }

    注意:fgets()函數(shù)會在字符串末尾(