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