Open minseo-jung opened 5 years ago
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> void p11_2_2() { int i = 0; int j = 0; int count = 0; int c = 0; int d = 0; char str[100]; char x = 0; printf("문자열을 입력하세요\n"); scanf("%s", str); while (i < 100) { i++; if (str[i] == 0) break; count++; } d = count++; c = count / 2; for (j = 0; j < c; j++) { x = str[d - j] ; str[d - j] = str[j]; str[j] = x; } printf("%s", str); return; }
sizeof()라는 함수를 사용하면 while (i < 100)에서 100을 직접 하드코딩 하지 않고 sizeof(str)이라고 하면 100이란 값이 나와. 변수 섹션에서 배웠던거였고, 배열크기를 포함해서 해당 변수가 가진 크기를 알아낼때 써 그럼 str이 100이되든 50이 되든 1000으로 늘리던 while의 조건문을 변경할 이유가 없어지지