bsc

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

root / semester_1 / letusc / luc074.c

luc074.c (1476B)


      1 /* Write a program that will read a line and delete from it all occurrences of the word 'the'.
      2 */
      3 
      4 /* Let Us C, Chap- 16 (Handling Multiple Strings), Qn No.: A(c) */
      5 
      6 /* This file is auto-generated by a bot. */
      7 /* This code is not compiled; it is for reference only. */
      8 
      9 
     10 #include <stdio.h>
     11 #include <string.h>
     12 #include <stdlib.h>
     13 #include <ctype.h>
     14 
     15 int main()
     16 {
     17     char str[100], res[100];
     18     int i = 0, j = 0;
     19 
     20     printf("Enter a line of text: ");
     21     gets(str);
     22 
     23     while (str[i] != '\0')
     24     {
     25         /* Check if the current segment matches "the" */
     26         /* To be a word 'the', it should effectively be surrounded by non-alphabets or start/end of string.
     27            For simplicity in this context, we check if str[i..] starts with "the" */
     28         
     29         if ((str[i] == 't' || str[i] == 'T') && 
     30             (str[i+1] == 'h' || str[i+1] == 'H') && 
     31             (str[i+2] == 'e' || str[i+2] == 'E') &&
     32             (str[i+3] == ' ' || str[i+3] == '\0'))
     33         {
     34             // Found "the" followed by space or null. Skip "the".
     35             i += 3; 
     36             
     37             // If it was followed by a space, we might want to skip the space too 
     38             // to avoid double spaces, but the problem says delete 'the'.
     39             // Let's just skip the word.
     40         }
     41         else
     42         {
     43             res[j] = str[i];
     44             j++;
     45             i++;
     46         }
     47     }
     48     res[j] = '\0';
     49 
     50     printf("Text after removing 'the': %s\n", res);
     51 
     52     return 0;
     53 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror