Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User input C programming [closed]

Tags:

c

user-input

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.

like image 994
user1880514 Avatar asked Dec 08 '12 17:12

user1880514


People also ask

What is %d in C programming?

%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.

What is the use of \b and \r in C?

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.

What is getch () in C language?

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 Answers

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:

  • http://www.codingunit.com/c-tutorial-first-c-program-hello-world
like image 125
paulsm4 Avatar answered Oct 06 '22 17:10

paulsm4