This code is wrong and need rewrite
if(ch=='a'){
if(ch=='a'){
ch='*';
}
}
putchar(ch);
As per assignment, when you encounter an 'a', you know what to do only when you know the next letter.
You need a variable to tell you if you have an 'a' on hold or not.
And you need to adapt the code to handle if a 'a' is on hold or not.
The code will look like:
if(ch=='a'){
if (a 'a' is on hold) {
putchar('*');
reset number of 'a' in hold
}
else {
add a 'a' in hold
}
}
else {
if (a 'a' is on hold) {
...
}
...
}
[Update]
Quote:
could you please explain what you mean by "in hold" and "on hold" english is not my first language
Sample input
Input on Hold Output
b b
a a
n a n
a a
a *
a a
n a n
a a
\n a \n
You can translate 'on hold' as waiting for next input. Said otherwise: you don't know what to do with a 'a' until you know if there is a second 'a'.