How to get the second word of string in C

2 Answers

0 votes
#include <stdio.h>
   
int main()
{
    char str[64] = "c c++ c# java php", second_word[24];
    int i = 0;
     
    while (str[i++] != ' ');
    
    int j = 0;
    while (str[i] != ' ')
        second_word[j++] = str[i++];
             
    puts(second_word);
  
    return 0;
}
  
/*
run:
  
c++
  
*/

 



answered Apr 16, 2018 by avibootz
0 votes
#include <stdio.h>
#include <string.h>
   
int main()
{
    char str[64] = "c c++ c# java php";
     
    char *second_word = strtok(str, " ");
    
    second_word = strtok(NULL, " ");
             
    puts(second_word);
  
  
    return 0;
}
  
/*
run:
  
c++
  
*/

 



answered Apr 16, 2018 by avibootz

Related questions

2 answers 142 views
1 answer 110 views
2 answers 848 views
848 views asked Apr 19, 2018 by avibootz
1 answer 107 views
1 answer 99 views
1 answer 124 views
1 answer 117 views
...