HackerRank C- Printing Tokens

Given a sentence,s, print each word of the sentence in a new line.

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5. int main() {
  6. char *s;
  7. int i=0;
  8. s =(char*) malloc(1024 * sizeof(char));
  9. scanf("%[^\n]", s);
  10. for( i=0; s[i]!='\0'; i++){
  11. if(s[i]==32)
  12. {
  13. printf("\n");
  14. }
  15. else
  16. printf("%c",s[i]);
  17. }
  18. return 0;
  19. }
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]

donate a cup of tea :)

Join Our Facebook Group

Share this solution


Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube