Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,907 questions

51,839 answers

573 users

How to delete a word from a string in C

1 Answer

0 votes
#include <stdio.h> 
#include <string.h> 
     
int main() 
{ 
    int j = 0, k = 0;
    char str[128] = "C is a general-purpose, procedural computer programming language";
    char word[30] = "computer"; 
    char arr2d[16][32] = {'\0'}; 

    // Convert the string into a 2D array    
    for (int i = 0; str[i] != '\0'; i++) { 
        if (str[i] == ' ') { 
            arr2d[k][j] = '\0'; 
            k++; 
            j = 0; 
        } 
        else { 
            arr2d[k][j] = str[i]; 
            j++; 
        } 
    } 
     
   str[0] = '\0';
        
   for (int i = 0; i < k; i++) { 
        if (strcmp(arr2d[i], word) != 0) { 
            strcat(strcat(str, arr2d[i]), " "); 
        } 
    } 
     
    puts(str);
    
    return 0;
} 





/*
run:

C is a general-purpose, procedural programming 

*/

 



answered Aug 24, 2021 by avibootz

Related questions

1 answer 124 views
4 answers 354 views
1 answer 64 views
1 answer 92 views
1 answer 170 views
...