C语言 用户输入 C 编程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13780209/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 04:42:13  来源:igfitidea点击:

User input C programming

cuser-input

提问by user1880514

I am trying to run a C program that requires the user input.

我正在尝试运行需要用户输入的 C 程序。

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

提示> .....

prompt> quit

提示>退出

I dont know how to prompt for user input in C, can anyone help with this?

我不知道如何在 C 中提示用户输入,有人可以帮忙吗?

Thanks in advance.

提前致谢。

回答by paulsm4

1) vi hello.c:

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

2) gcc -G -Wall -pedantic -o hello hello.c

3) ./hello

3)./你好

NOTE:

笔记:

The syntax will be different depending on your platform and compiler.

根据您的平台和编译器,语法会有所不同。

Here's another link:

这是另一个链接: