[c언어] 문자열 대문자 소문자로 변환 (아스키코드 사용)
2020. 12. 16. 11:13ㆍComputer Science/C
하나의 문자열(80자 이하)을 입력 받아서 문자열 안의 대문자는 소문자로, 소문자는 대문자로 바꾸는 프로그램을 작성한다.
#include <stdio.h>
int main(void)
{
char word[81], newWord[81];
int i, j = 0;
printf("Enter one word: ");
scanf("%s", word);
printf("word given: %s\n", word);
for (i = 0;word[i] != '\0';i++)
{
if (word[i] >= 65 && word[i] < 97)
{
newWord[j] = word[i] + 32;
j++;
}
else if (word[i] >= 97)
{
newWord[j] = word[i] - 32;
j++;
}
else
{
newWord[j] = word[i];
j++;
}
}
printf("new word: ");
newWord[j] = '\0';
printf("%s\n", newWord);
return 0;
}
결과

'Computer Science > C' 카테고리의 다른 글
[c언어] 같은 단어 판별하기 (0) | 2020.12.16 |
---|---|
[c언어] 문자열 palindrome (0) | 2020.12.16 |
[c언어] 2진수로 변환하기 (배열) (0) | 2020.12.16 |
[c언어] 난수 배열에 저장하여 평균 구하기 (0) | 2020.12.16 |
[c언어] 메르센소수 (0) | 2020.12.16 |