gpt4 book ai didi

c - 从平面文件中读取而不输出整个文件

转载 作者:行者123 更新时间:2023-11-30 20:26:11 25 4
gpt4 key购买 nike

好的,这是一个函数,它将读取文件并将值粘贴到屏幕上,但是,我希望能够打印特定行。现在,我应该创建一个循环来 printf 整个文件,但每次 datacount 不等于用户输入时执行 system("cls"); ,还是有更好的方法来执行此操作?

void NameSelect(void)
{
//Screen refresh
DataCount=1;

fFn=fopen("PDfirstN.txt","r"); //Opens student usernames
fscanf(fFn,"%16[^\n]%*c", stockF[DataCount].def); //Scans first line
fLn=fopen("PDlastN.txt","r"); //Opens student passwords
fscanf(fLn,"%16[^\n]%*c", stockL[DataCount].def2); //scans first line

do
{
printf("%d.", DataCount);
printf(" %s", stockF[DataCount].def);
printf(" %s", stockL[DataCount].def2);

DataCount=DataCount+1; //Next line counter
fscanf(fFn, "%16[^\n]%*c", stockF[DataCount].def); //Scans next line
fscanf(fLn, "%16[^\n]%*c", stockL[DataCount].def2);
printf("\n");
}
while(!feof(fFn)); //While there accounts in user name file

fclose(fFn);
fclose(fLn);
}

最佳答案

如果您不想显示任何内容,请不要调用 printf。

do
{
if (DataCount == DATA_COUNT_I_WANT) {
printf("%d.", DataCount);
printf(" %s", stockF[DataCount].def);
printf(" %s", stockL[DataCount].def2);
printf("\n");
}

DataCount=DataCount+1; //Next line counter
fscanf(fFn, "%16[^\n]%*c", stockF[DataCount].def); //Scans next line
fscanf(fLn, "%16[^\n]%*c", stockL[DataCount].def2);
}
while(!feof(fFn)); //While there accounts in user name file

关于c - 从平面文件中读取而不输出整个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26482313/

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