본문 바로가기

C/부스트코스

[부스트코스]C 언어 배열 7

반응형

Q>

string.h와 ctype.h의 라이브러리에 다른 어떤 함수가 있는지 확인해 보고, 어떤 함수를 어떻게 활용해 볼 수 있을지

생각해봅시다.
* string.h와 ctype.h를 검색해보시면 사람들이 잘 정리한 글을 찾을 수 있을 것입니다.

코딩에서 자기가 검색해서 공부해보는 것도 매우 중요하기 때문에 직접 찾아보도록 하겠습니다.

 

A>

string.h

#include <stdio.h>
#include <string.h>

// Take a string and get the length

int main(void)
{
    char str[100];
    scanf("%s", str);   // It is a standard input function in C language, allowing users to input various data according to various formats.
    printf("The string you entered is %s and its length is %lu.\n", str, strlen(str));      // %lu -> long int / 8byte / unsigned
}

ex2.c
0.00MB
ex2 (1)
0.02MB

 

ctype.h

#include <stdio.h>
#include <ctype.h>
#include <string.h>

// If the input string is in upper case, it is changed to lower case and if it is lower case, it is changed to upper case.

int main(void)
{
    char str[100];
    scanf("%s", str);

    for (int i = 0, n = strlen(str); i< n; i++)
    {
        if (islower(str[i])) // If the entered value is in lower case
        {
            str[i] = toupper(str[i]); // Change to uppercase

        }
        else if (isupper(str[i])) // If the entered value is in upper case
        {
            str[i] = tolower(str[i]); // Change to lowercase
        };
    }
    printf("%s\n", str);
}

ex3.c
0.00MB
ex3
0.02MB

 

https://www.boostcourse.org/cs112

 

모두를 위한 컴퓨터 과학 (CS50 2019)

부스트코스 무료 강의

www.boostcourse.org

 

반응형

'C > 부스트코스' 카테고리의 다른 글

[부스트코스]C 언어 배열 9  (0) 2021.01.27
[부스트코스]C 언어 배열 8  (0) 2021.01.27
[부스트코스]C 언어 배열 6  (0) 2021.01.26
[부스트코스]C 언어 배열 5  (0) 2021.01.26
[부스트코스]C 언어 배열 4  (0) 2021.01.26