fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include<string.h>
  4.  
  5. int main()
  6. {
  7. char *buffer;
  8. size_t bufsize = 32;
  9. size_t characters;
  10.  
  11. buffer = (char *)malloc(bufsize * sizeof(char));
  12. if( buffer == NULL)
  13. {
  14. perror("Unable to allocate buffer");
  15. exit(1);
  16. }
  17.  
  18. printf("Type something: ");
  19. characters = getline(&buffer,&bufsize,stdin);
  20. printf("%zu characters were read.\n",characters);
  21. printf("You typed: %s",buffer);
  22.  
  23.  
  24. char *end_str,*token2;
  25. char *token = strtok_r(buffer,";",&end_str);
  26. printf("token : %s \n", token);
  27. int count =0,wordcnt=0;
  28. while(token !=NULL)
  29. {
  30. char *end_token;
  31. count++;
  32. printf("outside count ------------------------%d\n", count);
  33. strtok_r(token," ",&end_token);
  34. while(token2!=NULL)
  35. {
  36. wordcnt++;
  37. printf("insdie count %d\n",wordcnt);
  38. printf("%s------------------- \n", token2);
  39. token2 = strtok_r(NULL," ",&end_token);
  40. }
  41. token = strtok_r(NULL, ";",&end_str);
  42. }
  43.  
  44. return(0);
  45. }
Success #stdin #stdout 0s 2304KB
stdin
Standard input is empty
stdout
Type something: 4294967295 characters were read.
You typed: token : (null)