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.
%d takes integer value as signed decimal integer i.e. it takes negative values along with positive values but values should be in decimal otherwise it will print garbage value. ( Note: if input is in octal format like:012 then %d will ignore 0 and take input as 12) Consider a following example.
A terminal emulator, when displaying \b would move the cursor one step back, and when displaying \r to the beginning of the line. If you print these characters somewhere else, like a text file, the software may choose. to do something else.
getch() method pauses the Output Console until a key is pressed. It does not use any buffer to store the input character. The entered character is immediately returned without waiting for the enter key. The entered character does not show up on the console.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With