Hey guys so for my assignment I have to replace two a's with an '*' from a string of unknown input length in C. The challenge is I am only allowed to use the getchar() and the putchar() function.
With an array it would have been easier but I am not even allowed to use that.
This is what I have tried
But it replaces all the a's with '*'.
Could someone just guide me to the correct path or just tell me which approach I should take?Code:#include <stdio.h> int ch; int main() { while ((ch = getchar()) !=EOF && ch != '\n' ) { if(ch=='a'){ if(ch=='a'){ ch='*'; } } putchar(ch); } putchar('\n'); return 0; }
Thank you in advance.