I'm doing a project where I need to convert a text from a file to morse. For this I stored the alphabet and its respective code morse (which is also in a file) into a struct..
The file "original.txt" is something like:
My name is Olivia
We are in 2019
3 plus 4 is 7
the file "morse.txt" is:
A .-*
B -...*
C -.-.*
D -..*
E .* //the file has the 26 letters and the 10 digits
etc..
now the only problem I have is:
warning: comparison between pointer and integer
> if (line[i] == l[j].letters){ (line 25)`
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/* Constants */
#define T_MORSE 8
#define Q_LETTERS 26
#define Q_NUMBERS 10
#define Q_MORSE (Q_LETTERS+Q_NUMBERS)
#define MAX_STRING_SIZE 50
typedef struct{ /* needs a position to the string finisher \0 */
char letters[5]; /* stores the letters , get it as a string , but use only the first letter */
char lettersMorse[T_MORSE];/* stores the respective morse symbols of the letters */
}alphabet;
alphabet l[Q_MORSE];
void process(const char *line) {
int j, i;
for (i = 0; line[i]; ++i) {
for ( j = 0; j < 37; ++j ){ //vector for morse letters
if (line[i] == l[j].letters){
printf("%s", l[j].lettersMorse);
printf(" ");}
}
}
}
int main(){
int cont=0,j;
FILE *arch;
arch = fopen("morse.txt","r");
if( arch == NULL ){
printf("ERROR");
return 0;
}
else{
while(fscanf(arch,"%s%s",l[cont].letters,l[cont].lettersMorse) != EOF){
l[cont].letters[1] = '\0'; /* eliminates unwanted characters */
for(j=0; j<strlen(l[cont].lettersMorse); j++){
if(l[cont].lettersMorse[j] == '*'){ /* if an asterisk is found */
l[cont].lettersMorse[j] = '\0'; /* eliminate asterisk */
break;
}
}
cont++; /*points to the next position of the vector */
}
}
fclose(arch);
FILE *fp;
char line[MAX_STRING_SIZE];
fp = fopen("original.txt", "r");
if (arch==NULL){
printf("ERROR");}
while (fgets(line,MAX_STRING_SIZE,fp) != NULL) {
process(line);
}
fclose(fp);
return 0;
}
'''