How to remove the first word from string in C

3 Answers

0 votes
#include <stdio.h>
#include <string.h>
   
int main()
{
    char str[32] = "c++ c c# java php";
    int i = 0, len = strlen(str);
     
    while (str[i++] != ' ');
    
    while(i--)
    {
        for (int j = i + 1; j <= len; j++)
            str[j - 1] = str[j];
    }
    
    puts(str);
 
    return 0;
}
  
/*
run:
  
c c# java php
  
*/

 



answered Apr 18, 2018 by avibootz
0 votes
#include <stdio.h>
   
int main()
{
    char str[32] = "c++ c c# java php";
    char *p = str;
    
    while (*p != 0 && *(p++) != ' ') {}
    
    puts(p);
 
    return 0;
}
  
/*
run:
  
c c# java php
  
*/

 



answered Apr 18, 2018 by avibootz
0 votes
#include <stdio.h>
#include <string.h>
   
int main()
{
    char str[32] = "c++ c c# java php";
    char *p = strchr(str, ' ');
    
    if (p != NULL)
        strcpy(str, p + 1);
        
    puts(str);
 
    return 0;
}
  
/*
run:
  
c c# java php
  
*/

 



answered Apr 18, 2018 by avibootz

Related questions

1 answer 86 views
2 answers 210 views
2 answers 237 views
1 answer 88 views
1 answer 152 views
2 answers 212 views
...