好吧,所以我还在学习C编程,我想要做的是从同一文件夹中的不同文本文件中读取特定行。所以我想说的是让我说我想从不同的文本文件中读取名称并显示它们。我一直试图这样做但我只能一次从一个文件中读取文本
下面是我的代码
void display_medicine()
{
system("cls");
const char *fil = "Medicines/";
const char *exec = ".txt";
char filename[50];
//snprintf(filename, sizeof filename, "%s%s%s", fil, medicineview, exec);
system("cls");
char medicinename[50];
char medavailability[20];
char companyname[100];
char dom[25];
char doe[50];
char price[20];
FILE *file;
file =fopen(filename,"r");
int num = 1;
if (file)
{
fgets(medicinename, sizeof(medicinename), file);
fgets(medavailability, sizeof(medavailability), file);
fgets(companyname, sizeof(companyname), file);
fgets(dom, sizeof(dom), file);
fgets(doe, sizeof(doe), file);
fgets(price, sizeof(price),file);
fclose(file);
gotoxy(10,3);
printf("================= %s VIEWING ================" "\n");
gotoxy(14,5);
printf("Name:\t\t\t%s", medicinename);
gotoxy(14,7);
printf("Availability:\t\t%s", medavailability);
gotoxy(14,9);
printf("Company Name:\t\t%s", companyname);
gotoxy(14,11);
printf("Date of Manufacture:\t%s", dom);
gotoxy(14,13);
printf("Date of Expiry:\t\t%s", doe);
gotoxy(14,15);
printf("Price:\t\t\t%s\n",price);
gotoxy(10,17);
printf("===============================================");
gotoxy(10,19);
printf("Press any key to go back!");
getch();
customerMenu();
}
我只能从一个文本文件而不是其他文本文件中读取内容
非常感谢任何帮助