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

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

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

Disclosure: My content contains affiliate links.

43,402 questions

56,366 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
...