Read User input in C language -


how prompt user enter country name such malaysia replace variable country1 malaysia ?

#include <stdlib.h> #include <stdio.h> #include <string.h>     writerecipe (int fd)    {      readdata ();      char country1[line_max] = "china";      static char* line1 = "starting country search client ...\n\n\n";      static char* line2 = "**********************************************";      static char* line3 = "welcome country info directory service!";      static char* line4 = "**********************************************\n\n";       write (fd, line1, strlen (line1) + 1); /* write first line */      write (fd, line2, strlen (line2) + 1); /* write second line */      write (fd, line3, strlen (line3) + 1); /* write third line */      write (fd, line4, strlen (line4) + 1); /* write fourth line */        puts("please enter country > ");      fgets(country1, sizeof country1,stdin);      printf ("\n%s capital       : %s\n", country1, getcapital (country1));      printf ("%s currency code : %s\n", country1, getcurrencycode (country1));    } 

how prompt user enter country name such malaysia

this how:

puts("please enter country name:"); 

now, if want actually read in user input:

char buf[line_max] = "china"; fgets(buf, sizeof buf, stdin); 

don't else. seriously. safe, simple , nice.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -