Well, I have a little problem, but First, I'll try to explain my program:
The user write a sentence, and it's saved in the char array FileContent[100]. Then, the user have to write five letters that is stored in the char array LE[5][2];. This letters are organized alphabetically by the program, and then, the user's sentence is printed originally and later without spaces. Here begins the problem...
If the user write only one word, the program works successfully, and in another array are stored the letters adequately depending on the letter being handled in the variable cont2. Are like coordinates.
But, when the user write a sentence, using spaces, the program doesn't work like I need to. The last process it is not carried out.
I hope it is understood, my English is not very good.
Thank you!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main()
{
char FileName[25], FileContent[100], FileChanged[210]={" "}, FileContentFixed[100];
char Table[6][6][6] =
{
{"","","","","","",},
{"","A","B","C","D","E",},
{"","F","G","H","IJ","K",},
{"","L","M","N\xA5","O","P",},
{"","Q","R","S","T","U",},
{"","V","W","X","Y","Z",}
};
char LE[5][2];
char temp[6];
int i, j, k;
int l=0;
char chara;
int a=0, cont, b, exit;
int cont2=0, cont3=0;
printf("\n Ahora escriba el contenido: ");
scanf(" %[^\n]",&FileContent);
fflush(stdin);
printf("\n Ahora digite EXCLUSIVAMENTE 5 letras, separadas con ENTER: \n");
do
{
gets(LE[l]);
l++;
fflush(stdin);
}while(l<5);
for(i=0; i<l-1; i++)
{
k=i;
strcpy(temp, LE[i]);
for(j=i+1; j<l; j++)
{
if(strcmp(LE[j], temp)<0)
{
k=j;
strcpy(temp, LE[j]);
}
}
strcpy(LE[k],LE[i]);
strcpy(LE[i],temp);
}
printf(" Las letras, en orden, son: ");
for(i=0; i<l; i++)
{
printf(" %s ",LE[i]);
}
strcpy(Table[0][1], LE[0]); //lE1 HORI
strcpy(Table[1][0], LE[0]); //LE1 VER
strcpy(Table[0][2], LE[1]); //LE2 HORI
strcpy(Table[2][0], LE[1]); //LE2 VER
strcpy(Table[0][3], LE[2]); //LE3 HORI
strcpy(Table[3][0], LE[2]); //LE3 VER
strcpy(Table[0][4], LE[3]); //LE4 HORI
strcpy(Table[4][0], LE[3]); //LE4 VER
strcpy(Table[0][5], LE[4]); //LE5 HORI
strcpy(Table[5][0], LE[4]); //LE5 VER
fflush(stdin);
printf("\n\n El contenido del archivo de texto (.txt), digitado por el usuario, es: %s",FileContent);
/* while((chara = fgetc(File1)) != EOF)
{
printf("%c",chara);
}*/
while(FileContent[a] != '\0')
{
if(FileContent[a]== ' ')
{
b=a;
exit=1;
while(exit==1)
{
fflush(stdin);
FileContent[b]=FileContent[b+1];
FileContent[b+1]=' ';
b++;
if(FileContent[b]=='\0')
{
exit=0;
}
}
}
a++;
}
printf("\n\n El contenido, sin espacios, es: %s",FileContent);
cont3=strlen(FileContent);
printf("\n\nHay %i caracteres en el arreglo.\n",cont3);
while(cont2<cont3)
{
printf("\n %i. %c",cont2,FileContent[cont2]);
printf(" %i\n",cont3);
switch(FileContent[cont2])
{
case 'a': printf("\n a: "); strcat(FileChanged,Table[0][1]); strcat(FileChanged,Table[1][0]); printf("%s",FileChanged); break;
case 'A': printf("\n A: "); strcat(FileChanged,Table[0][1]); strcat(FileChanged,Table[1][0]); printf("%s",FileChanged); break;
case 'b': printf("\n b: "); strcat(FileChanged,Table[0][2]); strcat(FileChanged,Table[1][0]); printf("%s",FileChanged); break;
case 'B': printf("\n B: "); strcat(FileChanged,Table[0][2]); strcat(FileChanged,Table[1][0]); printf("%s",FileChanged); break;
case 'c': printf("\n c: "); strcat(FileChanged,Table[0][3]); strcat(FileChanged,Table[1][0]); printf("%s",FileChanged); break;
case 'C': printf("\n C: "); strcat(FileChanged,Table[0][3]); strcat(FileChanged,Table[1][0]); printf("%s",FileChanged); break;
case 'd': printf("\n d: "); strcat(FileChanged,Table[0][4]); strcat(FileChanged,Table[1][0]); printf("%s",FileChanged); break;
case 'D': printf("\n D: "); strcat(FileChanged,Table[0][4]); strcat(FileChanged,Table[1][0]); printf("%s",FileChanged); break;
case 'e': printf("\n e: "); strcat(FileChanged,Table[0][5]); strcat(FileChanged,Table[1][0]); printf("%s",FileChanged); break;
case 'E': printf("\n E: "); strcat(FileChanged,Table[0][5]); strcat(FileChanged,Table[1][0]); printf("%s",FileChanged); break;
case 'f': printf("\n f: "); strcat(FileChanged,Table[0][1]); strcat(FileChanged,Table[2][0]); printf("%s",FileChanged); break;
case 'F': printf("\n F: "); strcat(FileChanged,Table[0][1]); strcat(FileChanged,Table[2][0]); printf("%s",FileChanged); break;
case 'g': printf("\n g: "); strcat(FileChanged,Table[0][2]); strcat(FileChanged,Table[2][0]); printf("%s",FileChanged); break;
case 'G': printf("\n G: "); strcat(FileChanged,Table[0][2]); strcat(FileChanged,Table[2][0]); printf("%s",FileChanged); break;
case 'h': printf("\n h: "); strcat(FileChanged,Table[0][3]); strcat(FileChanged,Table[2][0]); printf("%s",FileChanged); break;
case 'H': printf("\n H: "); strcat(FileChanged,Table[0][3]); strcat(FileChanged,Table[2][0]); printf("%s",FileChanged); break;
case 'i': printf("\n i: "); strcat(FileChanged,Table[0][4]); strcat(FileChanged,Table[2][0]); printf("%s",FileChanged); break;
case 'I': printf("\n I: "); strcat(FileChanged,Table[0][4]); strcat(FileChanged,Table[2][0]); printf("%s",FileChanged); break;
case 'j': printf("\n j: "); strcat(FileChanged,Table[0][4]); strcat(FileChanged,Table[2][0]); printf("%s",FileChanged); break;
case 'J': printf("\n J: "); strcat(FileChanged,Table[0][4]); strcat(FileChanged,Table[2][0]); printf("%s",FileChanged); break;
case 'k': printf("\n k: "); strcat(FileChanged,Table[0][5]); strcat(FileChanged,Table[2][0]); printf("%s",FileChanged); break;
case 'K': printf("\n K: "); strcat(FileChanged,Table[0][5]); strcat(FileChanged,Table[2][0]); printf("%s",FileChanged); break;
case 'l': printf("\n l: "); strcat(FileChanged,Table[0][1]); strcat(FileChanged,Table[3][0]); printf("%s",FileChanged); break;
case 'L': printf("\n L: "); strcat(FileChanged,Table[0][1]); strcat(FileChanged,Table[3][0]); printf("%s",FileChanged); break;
case 'm': printf("\n m: "); strcat(FileChanged,Table[0][2]); strcat(FileChanged,Table[3][0]); printf("%s",FileChanged); break;
case 'M': printf("\n M: "); strcat(FileChanged,Table[0][2]); strcat(FileChanged,Table[3][0]); printf("%s",FileChanged); break;
case 'n': printf("\n n: "); strcat(FileChanged,Table[0][3]); strcat(FileChanged,Table[3][0]); printf("%s",FileChanged); break;
case 'N': printf("\n N: "); strcat(FileChanged,Table[0][3]); strcat(FileChanged,Table[3][0]); printf("%s",FileChanged); break;
case 'o': printf("\n o: "); strcat(FileChanged,Table[0][4]); strcat(FileChanged,Table[3][0]); printf("%s",FileChanged); break;
case 'O': printf("\n O: "); strcat(FileChanged,Table[0][4]); strcat(FileChanged,Table[3][0]); printf("%s",FileChanged); break;
case 'p': printf("\n p: "); strcat(FileChanged,Table[0][5]); strcat(FileChanged,Table[3][0]); printf("%s",FileChanged); break;
case 'P': printf("\n P: "); strcat(FileChanged,Table[0][5]); strcat(FileChanged,Table[3][0]); printf("%s",FileChanged); break;
case 'q': printf("\n q: "); strcat(FileChanged,Table[0][1]); strcat(FileChanged,Table[4][0]); printf("%s",FileChanged); break;
case 'Q': printf("\n Q: "); strcat(FileChanged,Table[0][1]); strcat(FileChanged,Table[4][0]); printf("%s",FileChanged); break;
case 'r': printf("\n r: "); strcat(FileChanged,Table[0][2]); strcat(FileChanged,Table[4][0]); printf("%s",FileChanged); break;
case 'R': printf("\n R: "); strcat(FileChanged,Table[0][2]); strcat(FileChanged,Table[4][0]); printf("%s",FileChanged); break;
case 's': printf("\n s: "); strcat(FileChanged,Table[0][3]); strcat(FileChanged,Table[4][0]); printf("%s",FileChanged); break;
case 'S': printf("\n S: "); strcat(FileChanged,Table[0][3]); strcat(FileChanged,Table[4][0]); printf("%s",FileChanged); break;
case 't': printf("\n t: "); strcat(FileChanged,Table[0][4]); strcat(FileChanged,Table[4][0]); printf("%s",FileChanged); break;
case 'T': printf("\n T: "); strcat(FileChanged,Table[0][4]); strcat(FileChanged,Table[4][0]); printf("%s",FileChanged); break;
case 'u': printf("\n u: "); strcat(FileChanged,Table[0][5]); strcat(FileChanged,Table[4][0]); printf("%s",FileChanged); break;
case 'U': printf("\n U: "); strcat(FileChanged,Table[0][5]); strcat(FileChanged,Table[4][0]); printf("%s",FileChanged); break;
case 'v': printf("\n r: "); strcat(FileChanged,Table[0][1]); strcat(FileChanged,Table[5][0]); printf("%s",FileChanged); break;
case 'V': printf("\n r: "); strcat(FileChanged,Table[0][1]); strcat(FileChanged,Table[5][0]); printf("%s",FileChanged); break;
case 'w': printf("\n w: "); strcat(FileChanged,Table[0][2]); strcat(FileChanged,Table[5][0]); printf("%s",FileChanged); break;
case 'W': printf("\n W: "); strcat(FileChanged,Table[0][2]); strcat(FileChanged,Table[5][0]); printf("%s",FileChanged); break;
case 'x': printf("\n x: "); strcat(FileChanged,Table[0][3]); strcat(FileChanged,Table[5][0]); printf("%s",FileChanged); break;
case 'X': printf("\n X: "); strcat(FileChanged,Table[0][3]); strcat(FileChanged,Table[5][0]); printf("%s",FileChanged); break;
case 'y': printf("\n y: "); strcat(FileChanged,Table[0][4]); strcat(FileChanged,Table[5][0]); printf("%s",FileChanged); break;
case 'Y': printf("\n Y: "); strcat(FileChanged,Table[0][4]); strcat(FileChanged,Table[5][0]); printf("%s",FileChanged); break;
case 'z': printf("\n z: "); strcat(FileChanged,Table[0][5]); strcat(FileChanged,Table[5][0]); printf("%s",FileChanged); break;
case 'Z': printf("\n Z: "); strcat(FileChanged,Table[0][5]); strcat(FileChanged,Table[5][0]); printf("%s",FileChanged); break;
default: printf("\n Espaciooo ");
}
cont2=cont2+1;
}
getchar();
return 0;
}