i'm trying to make a program that if the previous letter is the same with the current letter that will be outputed will put a space between them...
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define T 100
#define S 255
int main(){
char Arrayinput[T][S];
char Arrayoutput[T][S*5];
int i, c, x;
for(i=0;i<T;i++){
for(c=0;c<S*5;c++){
Arrayoutput[i][c]=0;
}
}
scanf("%d", &x);
getchar();
for(i=0;i<x;i++){
gets(Arrayinput[i]);
}
for(i=0;i<x;i++){
for(c=0;c<strlen(Arrayinput[i]);c++){
switch(toupper(Arrayinput[i][c])){
case 'A':
if(Arrayoutput[i][c-1]=='2')
strcat(Arrayoutput[i]," ");
strcat(Arrayoutput[i],"2"); break;
case 'B':
if(Arrayoutput[i][c-1]=='2')
strcat(Arrayoutput[i]," ");
strcat(Arrayoutput[i],"22"); break;
case 'C':
if(Arrayoutput[i][c-1]=='2')
strcat(Arrayoutput[i]," ");
strcat(Arrayoutput[i],"222"); break;
} } }
for(i=0;i<x;i++){
printf("case #%d:%s\n",i+1,Arrayoutput[i]);
}
system("pause");
return 0;
for some case..
if i input.. bca it out puts 22 222 2 which is correct.. such as cab = 222 22 2 bac = 22 2 222
but when ever i input abc it out puts... 2 22222... i dont know why... pls help?