Hi guys. Im doing a morse code encoder and Im struggling with some things. Does any one knows why it doesnt convert my string when I compile? Do you know tell me if its ok the connection between the char function and the main one?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
typedef struct {
char letters;
char lettersMorse[6];
}alphabet;
alphabet l[37];
char encode (const char *s)
{
int i, j;
for ( i = 0; s[i]; ++i )
{
for ( j = 0; j < 37; ++j )
{
if ( toupper(s[i]) == l[j].letters )
{
printf("%s", l[j].lettersMorse);
}
}
}
}
int main()
{
int i=0;
FILE *arch;
arch = fopen("morse1.txt", "r");
if (arch==NULL){
printf("ERROR");
}
else{
while (!feof(arch)){
fscanf(arch, "%c %s\n", &l[i].letters, l[i].lettersMorse);
// store the alphabet letters in 'letters' and its respective morse
// code in 'lettersMorse' of the struct
}
}
fclose(arch);
char text[50];
printf("Write your text to be encode\n");
scanf(" %s", text);
encode(text);
return 0;
}