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. }




codesadda.com

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