GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Wednesday, March 16, 2011

C - Using malloc

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

#define N 20

int main()
{
    system("color f0");

    printf("Enter your name: ");
    char *name = malloc(sizeof(char));
    fflush(stdin);                      // free the buffer
    gets(name);

    printf("Your age: ");
    int age;
    scanf("%d", &age);

    puts("");
    printf("Your data:\n");
    printf("Name: %s\n", name);
    printf("Age : %d\n", age);

    puts("");
    system("pause");

    return 0;
}

Share/Bookmark

No comments:

Post a Comment