bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

luc094.c (1551B)


      1 /*
      2  * Author  : Amit Dutta <amitdutta4255@gmail.com>
      3  * Date    : 08 Feb 2026
      4  * Repo    : https://github.com/notamitgamer/bsc
      5  * License : MIT License (See the LICENSE file for details)
      6  */
      7 
      8 /* Read a text file, delete the words 'a', 'the', 'an' and replace each with a blank space. Write to new file.
      9 */
     10 /* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(j) */
     11 
     12 /* This file is auto-generated by a bot. */
     13 /* This code is not compiled; it is for reference only. */
     14 
     15 
     16 #include <stdio.h>
     17 #include <stdlib.h>
     18 #include <string.h>
     19 #include <ctype.h>
     20 
     21 void create_article_file();
     22 
     23 int main()
     24 {
     25     FILE *fp, *ft;
     26     char word[100];
     27 
     28     create_article_file();
     29 
     30     fp = fopen("articles.txt", "r");
     31     ft = fopen("clean.txt", "w");
     32 
     33     if (!fp || !ft) exit(1);
     34 
     35     // Basic word-by-word processing using fscanf
     36     // Note: fscanf skips whitespace, so original spacing formatting 
     37     // might be lost, but it effectively filters words.
     38     
     39     while (fscanf(fp, "%s", word) != EOF)
     40     {
     41         if (strcasecmp(word, "a") == 0 || 
     42             strcasecmp(word, "an") == 0 || 
     43             strcasecmp(word, "the") == 0)
     44         {
     45             fputc(' ', ft); // Replace with blank
     46         }
     47         else
     48         {
     49             fprintf(ft, "%s ", word);
     50         }
     51     }
     52 
     53     printf("Processed file. Articles removed in 'clean.txt'.\n");
     54 
     55     fclose(fp);
     56     fclose(ft);
     57     return 0;
     58 }
     59 
     60 void create_article_file()
     61 {
     62     FILE *f = fopen("articles.txt", "w");
     63     fprintf(f, "The quick brown fox jumps over a lazy dog. It was an honour.");
     64     fclose(f);
     65 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror