How to fill char array from stdin in C

1 Answer

0 votes
#include <stdio.h>

int main(int argc, char **argv) 
{ 
    char name[13];
    
    printf("What is your name? ");
    fgets(name, 13, stdin);
    printf("your name is: %s\n", name);
    
    return(0);
}




/*
run1:

What is your name? sea
your name is: sea


run2:
What is your name? abcdefghijklmnopqrstuvwxyz
your name is: abcdefghijkl
// note: name[12] is '\n' (null)

*/


answered May 27, 2015 by avibootz
edited May 27, 2015 by avibootz

Related questions

...