I am having difficulties printing out the correct number of character in a RLE program. I have already made it work with arrays and Im looking for a different approach.Here is the code :
#include <stdio.h>
int main ()
{
char elem,elem1;
int n=1;
while ((elem=getchar())!=EOF && elem!='\n'){
if ((elem1=getchar())==elem){
n++;
}
printf("%d%c",n,elem);
n=1;
}
printf("\n");
return 0;
}
For example when I enter --> ttyyy the output is 2t2y1y. Already tried adding an else statement but it never actually enters the statement.Output should have been 2t3y.
Thank you in advance.