User input C programming
1) vi hello.c:
#include <stdio.h>
#define MAX_LEN 80
int
main (int argc, char *argv[])
{
char a_word[MAX_LEN];
printf ("Enter a word: ");
scanf ("%s", a_word);
printf ("You entered: %s\n", a_word);
return 0;
}
2) gcc -G -Wall -pedantic -o hello hello.c
3) ./hello
NOTE:
The syntax will be different depending on your platform and compiler.
Here's another link:
user1880514
Updated on December 09, 2020Comments
-
user1880514 over 3 years
I am trying to run a C program that requires the user input.
The program is supposed to prompt the user to enter certain words and I am supposed to search for those words in a data structure.
so the command line is supposed to look like this:
prompt>
the user will enter multiple words to search and I need access to each one of those words separately. AFter the program is done executing on those words, the program needs to restart and keep running until the user types in "quit" in the prompt.
Ex: prompt> ..... (program will run based on the words input)
prompt> .....
prompt> .....
prompt> quit
I dont know how to prompt for user input in C, can anyone help with this?
Thanks in advance.