Ich bin Anfänger auf C-Programmierung. Ich habe Programm geschrieben, um Zeichenkette in morze alphabetische Zeichenfolge mit Punkten und Strichen umzuwandeln. Aber printf() funktioniert nicht. Schreibe ich etwas falsch gemacht? (Ehrlich, dieses Programm für den Prozessor ATMega verwenden. Aber Hauptproblem in meinem Code, so nicht aufpasst es)Printf() funktioniert nicht beim Konvertieren der Zeichenfolge in C
#include <avr/io.h>
#include <util/delay.h>
#include <stdio.h>
#include <string.h>
int main()
{
char morze[] = "";
char buf[] ="Name Surname Patronymic";
int a = 0;
char *p = strtok (buf, " ");
char *each_word[3];
while (p != NULL)
{
each_word[a++] = p;
p = strtok (NULL, " ");
}
for(int i = 0; i < strlen(each_word); i++){
for(int j = 0; j < strlen(each_word[i]); j++){
if(tolower(each_word[i][j]) == "a") strcat(morze,".- ");
else if(tolower(each_word[i][j]) == "b") strcat(morze,"-... ");
else if(tolower(each_word[i][j]) == "c") strcat(morze,"-.-. ");
else if(tolower(each_word[i][j]) == "d") strcat(morze,"-.. ");
else if(tolower(each_word[i][j]) == "e") strcat(morze,". ");
else if(tolower(each_word[i][j]) == "f") strcat(morze,"..-. ");
else if(tolower(each_word[i][j]) == "g") strcat(morze,"--. ");
else if(tolower(each_word[i][j]) == "h") strcat(morze,".... ");
else if(tolower(each_word[i][j]) == "i") strcat(morze,".. ");
else if(tolower(each_word[i][j]) == "j") strcat(morze,".--- ");
else if(tolower(each_word[i][j]) == "k") strcat(morze,"-.- ");
else if(tolower(each_word[i][j]) == "l") strcat(morze,".-.. ");
else if(tolower(each_word[i][j]) == "m") strcat(morze,"-- ");
else if(tolower(each_word[i][j]) == "n") strcat(morze,"-. ");
else if(tolower(each_word[i][j]) == "o") strcat(morze,"--- ");
else if(tolower(each_word[i][j]) == "p") strcat(morze,".--. ");
else if(tolower(each_word[i][j]) == "q") strcat(morze,"--.- ");
else if(tolower(each_word[i][j]) == "r") strcat(morze,".-. ");
else if(tolower(each_word[i][j]) == "s") strcat(morze,"... ");
else if(tolower(each_word[i][j]) == "t") strcat(morze,"- ");
else if(tolower(each_word[i][j]) == "u") strcat(morze,"..- ");
else if(tolower(each_word[i][j]) == "v") strcat(morze,"...- ");
else if(tolower(each_word[i][j]) == "w") strcat(morze,".-- ");
else if(tolower(each_word[i][j]) == "x") strcat(morze,"-..- ");
else if(tolower(each_word[i][j]) == "y") strcat(morze,"-.-- ");
else if(tolower(each_word[i][j]) == "z") strcat(morze,"--.. ");
}
}
printf(buf);
int b = 0;
char *q = strtok (morze, " ");
char *each_letter[3];
while (q != NULL)
{
each_letter[b++] = q;
q = strtok (NULL, " ");
}
for(int i = 0; i < strlen(each_letter); i++){
for(int j = 0; j < strlen(each_letter[i]); j++){
if(each_letter[i][j] == ".") {printf("1");}
else if(each_letter[i][j] == "-") {printf("2");}
}
}
}
habe ich versucht, aber drucken immer noch nicht nichts drucken –