User Tools

Site Tools


haas:spring2013:common:pointer_arrays_char_input

char input with pointer arrays

1
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    char *initials, i = 0;
 
    name = (char *) malloc (sizeof(char) * 4);
 
    fprintf(stdout, "Enter a 3 character set of initials and hit ENTER: ");
    *(initials+i) = fgetc(stdin);
    i = i + 1;
    *(initials+i) = fgetc(stdin);
    i = i + 1;
    *(initials+i) = fgetc(stdin);
    i = i + 1;
    *(initials+i) = fgetc(stdin);
 
    fprintf(stdout, "You entered %s\n", initials);
 
    return(0);
}
haas/spring2013/common/pointer_arrays_char_input.txt · Last modified: 2013/02/15 16:06 by 127.0.0.1