luc094.c ​
Metadata ​
- Author — Amit Dutta
- Last updated — 08 Feb 2026
- License — MIT License (See the LICENSE file for details)
Problem Statement ​
Problem Statement
Read a text file, delete the words 'a', 'the', 'an' and replace each with a blank space. Write to new file.
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
void create_article_file();
int main()
{
FILE *fp, *ft;
char word[100];
create_article_file();
fp = fopen("articles.txt", "r");
ft = fopen("clean.txt", "w");
if (!fp || !ft) exit(1);
// Basic word-by-word processing using fscanf
// Note: fscanf skips whitespace, so original spacing formatting
// might be lost, but it effectively filters words.
while (fscanf(fp, "%s", word) != EOF)
{
if (strcasecmp(word, "a") == 0 ||
strcasecmp(word, "an") == 0 ||
strcasecmp(word, "the") == 0)
{
fputc(' ', ft); // Replace with blank
}
else
{
fprintf(ft, "%s ", word);
}
}
printf("Processed file. Articles removed in 'clean.txt'.\n");
fclose(fp);
fclose(ft);
return 0;
}
void create_article_file()
{
FILE *f = fopen("articles.txt", "w");
fprintf(f, "The quick brown fox jumps over a lazy dog. It was an honour.");
fclose(f);
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50