Here is a program in C that illustrates the use of fscanf() to read a text file:
#include <stdio.h>
int main() {
FILE *filePointer;
char buffer[100];
// Open the file in read mode
filePointer = fopen("example.txt", "r");
// Check if the file is opened successfully
if (filePointer == NULL) {
printf("Error opening the file.\n");
return 1;
}
// Read data from the file using fscanf until the end of the file
while (fscanf(filePointer, "%s", buffer) != EOF) {
// Print the data read from the file
printf("%s\n", buffer);
}
// Close the file
fclose(filePointer);
return 0;
}