Notice
Recent Posts
Recent Comments
Link
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Tags
more
Archives
Today
Total
관리 메뉴

문타쿠, 공부하다.

[C언어 코딩 도장] Unit 45. 연습문제 및 심사문제 본문

C언어/C언어 코딩 도장

[C언어 코딩 도장] Unit 45. 연습문제 및 심사문제

개발새발 문타쿠 2023. 10. 2. 23:42

45.6 연습문제: 문자열 자르기

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

int main(void)
{
    char s1[40] = "Alice's Adventures in Wonderland";

    char* ptr = strtok(s1, " ");

    while (ptr != NULL)
    {
        printf("%s\n", ptr);
        ptr = strtok(NULL, " ");
    }

    return 0;
}


45.7 심사문제: 문자열 자르기

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

int main(void)
{
    char domain[61];

    printf("인터넷 도메인 입력>> ");
    scanf("%s", domain);
    printf("\n");

    char* ptr = strtok(domain, ".");

    while (ptr != NULL)
    {
        printf("%s\n", ptr);
        ptr = strtok(NULL, ".");
    }

    return 0;
}


45.8 심사문제: 특정 단어 개수 세기

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

int main(void)
{
    char sentence[1001];
    int count = 0;

    printf("문자열을 입력하세요.\n");
    printf(">> ");
    scanf("%[^\n]s", sentence);
    printf("\n");

    char* ptr = strtok(sentence, " ,.");

    while (ptr != NULL)
    {
        if(strcmp(ptr, "the") == 0)
            count++;

        ptr = strtok(NULL, " ,.");
    }

    printf("the의 개수는 %d개입니다.", count);

    return 0;
}

*입력 값

the grown-ups' response, this time, was to advise me to lay aside my drawings of boa constrictors, and whether from the inside or the outside and devote myself instead to geography history ari thmetic, grammar That is why at the age of six I gave up what might have been a magni ficent career as a painter. I had been disheartened by the failure of my Drawing Number One and my Drawing Number TwO. forever explaining things to the.