GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Tuesday, March 15, 2011

C - getchar, putchar and malloc

#include <stdio.h>
#include <stdlib.h>

#define N 20

int main()
{
    system("color 2f");

    // use malloc for avoiding error of system
    char *data = malloc(sizeof(char));

    int i;
    for(i=0;i<N;i++){
        data[i] = getchar();
    }

    int k;
    for(k=0;k<N;k++){
        putchar(data[k]);
    }

    return 0;
}

Share/Bookmark

1 comment: