1015실습 - kyagrd/cprog2018Fall GitHub Wiki

hw3 관련

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

#define OUT 0
#define IN 1

int main()
{
    char c;
    int wordcount = 0; // 총 단어 개수
    int ulwdcount = 0; // 대문자로 시작해 소문자로 끝나는 단어 개수

    int state = OUT;

    while (EOF != (c = getchar()))
    {
        if ( isspace(c) ) state = OUT;
        else if ( OUT == state )
        { // 여기가 첫 글자가 처리되는 부분이다
            state = IN;
            ++wordcount;
            printf("\nFIRST LETTER: %c\n", c); // 디버깅을 위한 출력 (첫글자라는 거 확인)
        }
    }

    printf("%d\n", wordcount); // 전체 단어 개수
    printf("%d\n", ulwdcount); // 첫글자 대문자이고 마지막 글자 소문자인 단어 개수

    return 0;
}
#include <stdio.h>
#include <stdlib.h>
// character type 을 줄여서
#include <ctype.h> // isspace, isupper, islower

int main()
{
    if (isupper('A')) printf("A is upper character\n");
    else printf("A is not upper character\n");

    if (isupper('a')) printf("a is upper character\n");
    else printf("a is not upper character\n");

    if (islower('A')) printf("A is lower character\n");
    else printf("A is not lower character\n");

    if (islower('a')) printf("a is lower character\n");
    else printf("a is not lower character\n");

    return 0;
}

포인터로 swap 함수 작성 예제

#include <stdio.h>
#include <stdlib.h>
// character type 을 줄여서
#include <ctype.h> // isspace, isupper, islower

// 포인터
//
// int n = 3;
// int *p = &n;

// p == &n; // n의 주소값
// n == *p; // 3

// p1과 p2가 가리키는 주소에 저장된 내용을 바꿔치기

/*
void swap(int x, int y)
{
    int tmp = x;
    x = y;
    y = tmp;
    printf("inside swap: %d %d\n", x, y);
}
*/
void swap(int *p1, int *p2)
{
    int tmp = *p1;
    *p1 = *p2;
    *p2 = tmp;
    printf("inside swap: %d %d\n", *p1, *p2);
}

int main(void)
{
    int x = 3;
    int y = 5;

    printf("%d %d\n", x, y);
    swap(&x, &y);
    printf("outside swap: %d %d\n", x, y);

    /*
    int tmp = x; // tmp==3, x==3, y==5
    x = y; // tmp==3, x==5, y==5
    y = tmp;  // tmp==3, x==5, y==3

    printf("%d %d\n", x, y);
*/
    return 0;
}
#include <stdio.h>
#include <stdlib.h>
// character type 을 줄여서
#include <ctype.h> // isspace, isupper, islower

// 포인터가 가리키는 위치를 바꿀 수 있다
int main(void)
{
    char str[1024] = "abcdefg";
    // putchar를 이용해 한글자씩 찍어보기
    char *p = str;

    while (*p) putchar(*p++);

    return 0;


    int a[5] = { 10, 11, 12, 13, 14 };

    for (int i=0; i<5; ++i) printf("%d\n", a[i]);
    printf("=========================\n");
    for (int *p=a; p<a+5; ++p) printf("%d\n", *p);

    /*
    int n1 = 3;
    int n2 = 4;
    int n3 = 5;

    int *p = &n1;
    printf("%d\n", *p);
    p = &n2;
    printf("%d\n", *p);
    p = &n3;
    printf("%d\n", *p);
    */
    return 0;
}


// 포인터
//
// int n = 3;
// int z = 5;
// n = 4; // 변수의 값 변경
// int *p = &n;
// p = &z; // 포인터의 값(가리키는 주소) 변경

// p == &n; // n의 주소값
// n == *p; // 3

// p1과 p2가 가리키는 주소에 저장된 내용을 바꿔치기

/*
void swap(int x, int y)
{
    int tmp = x;
    x = y;
    y = tmp;
    printf("inside swap: %d %d\n", x, y);
}
*/
void swap(int *p1, int *p2)
{
    int tmp = *p1;
    *p1 = *p2;
    *p2 = tmp;
    printf("inside swap: %d %d\n", *p1, *p2);
}

int main4444444444444444444(void)
{
    int x = 3;
    int y = 5;

    printf("%d %d\n", x, y);
    swap(&x, &y);
    printf("outside swap: %d %d\n", x, y);

    /*
    int tmp = x; // tmp==3, x==3, y==5
    x = y; // tmp==3, x==5, y==5
    y = tmp;  // tmp==3, x==5, y==3

    printf("%d %d\n", x, y);
*/
    return 0;
}
⚠️ **GitHub.com Fallback** ⚠️