Please refer to the code below.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
int main()
{
char* n[5];
char* name;
FILE* fp = NULL;
int cnt = 0;
fp = fopen("Word.txt", "r");
if (fp == NULL)
{
fprintf(stderr, "File Open Error!\n");
exit(1);
}
for (int i = 0; i < 5; i++)
{
name = (char*)malloc(sizeof(char) * MAX);
fgets(name, MAX, fp);
n[i] = name;
printf("%s", name);
}
printf("\n\n");
for (int i = 0; i < 5; i++)
printf("%s", n[i]);
for (int i = 0; i < 5; i++)
free(n[i]);
fclose(fp);
return 0;
}
Run Results
688 Error in x, y, and format string must not be None
608 Who developed the "avformat-59.dll" that comes with FFmpeg?
1132 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
717 GDB gets version error when attempting to debug with the Presense SDK (IDE)
673 M2 Mac fails to install rbenv install 3.1.3 due to errors
© 2025 OneMinuteCode. All rights reserved.