简体   繁体   English

自动执行C程序的用户输入

[英]Automating user input for C program

I am planing to make a C program using array of structures which takes input as strings ie, name of movie and genre(4 different genres): 我计划使用结构数组制作一个C程序,该结构将输入作为字符串,即电影名称和流派(4种不同流派):

struct movie
   {
      char name[30];
      char genre[4][10];
   }m[30];

void main()
{
   int i,j;
   for(i=0;i<30;++i)
   {
      scanf("%s",m[i].name);                     //Removing gets
      for(j=0;j<4;++j)
      {
          scanf("%s",m[i].genre[j]);             //Removing gets
      }
   }
}

I want to automate the user input of the program from a pre-defined source eg a text file, so that I don't have to insert all the input manually. 我想从预定义的源(例如文本文件)中自动执行程序的用户输入,因此我不必手动插入所有输入。 Is there a script(python/bash) to do this or any other method that can make my job easier for 100s of input. 有没有执行此操作的脚本(python / bash)或任何其他方法,可以使我的工作更轻松地进行数百次输入。

The reason behind using the C program is to store the inputs in a file for future use. 使用C程序的原因是将输入存储在文件中以备将来使用。

Write it to accept input from the keyboard. 编写它以接受来自键盘的输入。 Then use input redirection: 然后使用输入重定向:

myprogram.out < SampleTestData.txt

Uses the SampleTestData.txt file as if it were keyboard input. 使用SampleTestData.txt文件,就好像它是键盘输入一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM