Wednesday, October 10, 2007

Jawaban No Pause Telegraph

#include
#include
#include
char Cek(char x[]);
void Cetak(char x[]);
void createEmpty(char x[]);
int main()
{
char N;
int perhatian=0;
int i=0;
char tampung[10];
char hasil[10];
int j=0;
char temp=0;
bool cetak=true;
bool min=true;
createEmpty(hasil);
createEmpty(tampung);
while ( scanf( "%c", &N ) != EOF )
{
if ((int)N != 10)
{
tampung[i++]=N;
if(Cek(tampung)!='O')
{
i=0;
perhatian=0;
hasil[j++]=Cek(tampung);
createEmpty(tampung);
}
else
perhatian++;
}
else
{
i=0;
j=0;
if(perhatian==0)
Cetak(hasil);
else
printf("could not be translated\n");
createEmpty(hasil);
createEmpty(tampung);
perhatian=0;
}
}

return 0;
}

char Cek(char x[])
{
if (strcmp(x,".--")==0) return 'A';
else if(strcmp(x,"-.")==0) return 'B';
else if(strcmp(x,"---")==0) return 'C';
else if(strcmp(x,"..")==0) return 'D';
else if(strcmp(x,"--..")==0) return 'E';
else if(strcmp(x,"--.-")==0) return 'F';
else if(strcmp(x,".-.")==0) return 'G';
else
return 'O';
}

void Cetak(char x[])
{
int i=0;
while(x[i]!=NULL)
{
printf("%c",x[i]);
i++;
}
printf("\n");
}
void createEmpty(char r[])
{
for(int x=0;x<10;x++)
{
r[x]=NULL;
}
}

1 comment:

Anonymous said...

Nice dispatch and this enter helped me alot in my college assignement. Thanks you as your information.