gpt4 book ai didi

C编程: fscanf to fgets code

转载 作者:太空宇宙 更新时间:2023-11-04 04:45:33 24 4
gpt4 key购买 nike

<分区>

我有一个文本文件,其中包含一些我想输出到屏幕上的句子。

The time to come.
Normal, common, or expected.
A special set of clothes worn by all the members of a particular group or organization
Already made use of, as in a used car.
Bing
A circle of light shown around or above the head of a holy person.
The god of thunder.
An act that is against the law.
Long dress worn by women.
Odd behaviour.

这是我用来将单词输出到这些定义的代码,但是 Scanf 不喜欢空格,所以有人可以编辑这段代码以输出上面的定义,谢谢。

应该早点说,但一次输出应该是 1 个句子。

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

FILE *fp;
int main(void)
{

struct store
{
char id[128];
}stock[10];

int printnum;
int allrec=0;
int startrec=0;

fp=fopen("Test 24 Definitions.txt","r");
printf("i");
fscanf(fp,"%s",&stock[startrec].id);

while(!feof(fp))
{
printf("%s", stock[startrec].id);
printf(" \n");
getch();
startrec=startrec+1;
allrec=startrec;
fscanf(fp,"%s",&stock[startrec].id);
}

fclose(fp);

printf("\n\n\n\n");
int i;
for (i=0; i<allrec; i++)
{
printf("%s\n",stock[i].id);
getch();
}
}

使用 fgets 的示例代码将不胜感激

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com