我正在尝试编写一个接受MadLib大纲作为.txt文件的C程序。该程序然后要求用户输入一系列短语放入Madlib中。我有这部分完整。但是,我希望能够将用户输入的MadLib短语&插入到早先打开的.txt文件中。然后,我希望能够允许用户将完成的MadLib保存在不同的.txt文件名下。 MadLib大纲在其中放置了关键字,表示用户输入的单词应该放在哪里。 (见下文)。带重定向输入和输出的MadLib C程序
我应该如何去用这些用户输入的短语替换这些占位符?
马德利布大纲.txt文件:
One of the most <adjective> characters in fiction is named
"Tarzan of the <plural-noun>." Tarzan was raised by a/an
<noun> and lives in the <adjective> jungle in the
heart of darkest <place>. He spends most of his time
eating <plural-noun> and swinging from tree to <noun>.
Whenever he gets angry, he beats on his chest and says,
"<funny-noise>!" This is his war cry. Tarzan always dresses in
<adjective> shorts made from the skin of a/an <noun>
and his best friend is a/an <adjective> chimpanzee named
Cheetah. He is supposed to be able to speak to elephants and
<plural-noun>. In the movies, Tarzan is played by <person's-name>.
您可以从'fgets'开始从您的文件中读取一行,然后使用'strchr'来查找尖括号。然后将文本复制出来,并将尖括号中的文本替换为您阅读的文字。我不确定除了编写程序来完成您所描述的内容之外,还有别的方法可以回答您的问题。如果您有更具体的问题,请告诉我。 – yellowantphil 2014-11-06 01:15:50