IT/솔루션) 난 정말C... 없다구요

24장. 배열과 포인터, 포인터 연산) 문제 24-1 [포인터 덧셈 뺄셈 연산] - 1

돔찌 2019. 4. 18. 18:11

<2016. 9. 26. 21:13>

24장. 배열과 포인터, 포인터 연산) 문제 24-1 [포인터 덧셈 뺄셈 연산] - 1

 

/*
프로그램 상에  다음과 같은 문자열을 선언하자.
 char * str = "He Is My Best Friend!";
그리고 포인터 str을 이용해 문자열에 저장된 대문자의 개수가 몇 개인지 세어보는 프로그램을 작성하자.
이 문제의 해결을 위해 포인터 str을 이용한 포인터 연산을 해야만 한다.
*/
#include<stdio.h>
#include<stdlib.h>
int main(void) {
	char * str = "He Is My Best Frined!";
	int i = 0;
	int count = 0;
	while (1) {
		if (str[i] == '\0')
		   break; else if (str[i] > 'A' && str[i] < 'Z')
		   count++;
		i++;
	}
	printf("%d\n", count);
	/*
 for (i = 0; str[i] ==  'B'; i++)
 {
  count++;
 }
 printf("%d", count);
*/
	system("pause");
	return 0;
}