hiverkiya / Dennis-Ritchie-C-Solutions

Solutions to Second Edition of Dennis-Ritchie's Book
https://hiverkiya.github.io/Dennis-Ritchie-C-Solutions/
MIT License
36 stars 17 forks source link

Exercise 1.12 - Print the input one word per line.c #4

Open ANIL80531 opened 11 months ago

ANIL80531 commented 11 months ago

Your code will not work if there is tab between words. try this

#include<stdio.h>
int main(){
     int c=0;
     int state=0;
     while((c=getchar())!=EOF){
         if((c==' '||c=='\t'||c=='\n')&&state==1){
             putchar('\n');
             state=0;
         }
        else{
             putchar(c);
             state=1;
         }
     }
}
hiverkiya commented 5 months ago

@ANIL80531 can you please make a pull request related to this? I'm really sorry, it took me a long time to review the changes