Kodi:
#include
#include
#include
#include /*per STDIN_FILENO*/
#include
unsigned char shkronja[39] = {
'A', 'B', 'C', 'D', 'E', 'F',
'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', '0', '1', '2', '3',
'4','5', '6', '7', '8','9', '.',
',', '?'
};
char *mors[39] = {
".-", "-...", "-.-.", "-..", ".",
"..-.","--.","....", ".." , ".---",
"-.-", ".-..", "--", "-.", "---",
".--.", "--.-", ".-.", "...", "-",
"..-", "...-", ".--", "-..-", "-.--",
"--..", "-----", ".----","..---", "...--",
"....-", ".....", "-....", "--...", "---..",
"----.", ".-.-.-", "--..--", "..--.."
};
#define NUMRA_PIKESIME 13
#define SHKRONJA 26
#define GJAT_RRESHTI 80
#define MAX_GJAT_MORS 6 /*gjatesia max per enkodimin e nje shkronje ne mors*/
int morsshkronje(char *str) {
int y;
for(y = 0; y < SHKRONJA+NUMRA_PIKESIME; y++)
#ifdef DEBUG
printf("morsshkronj: pas for(y= '0' && germe <= '9') || germe == '.' || germe == ',' || germe == '?') {
/*eshte numer ose shenje pikesimi */
for(y = 0; y < NUMRA_PIKESIME; y++)
if ( germe == shkronja[SHKRONJA+y] ) {
str = (char *)malloc(sizeof(char)*MAX_GJAT_MORS);
if (str == NULL)
return NULL;
(void)strncpy(str,mors[SHKRONJA+y], MAX_GJAT_MORS);
#ifdef DEBUG
printf("shkronjemors: str = \"%s\"\n",str);
#endif
}
} else {
for(y = 0; y < SHKRONJA; y++) {
#ifdef DEBUG
printf("shkronjemors: ne germe=%c : shkronja[y]=%c\n",
germe, shkronja[y]);
#endif
if (germe == shkronja[y] ) {
#ifdef DEBUG
printf("shkronjemors: ne germe == shkronja[y]\n");
#endif
str = (char*)malloc(sizeof(char)*6);
if (str == NULL)
return NULL;
(void)strncpy(str, mors[y], MAX_GJAT_MORS);
#ifdef DEBUG
printf("shkronjemors: str = \"%s\"\n",str);
#endif
}
}
}
return str;
} /*fund shkronje-mors() */
int main(int argc, char *argv[]) {
/* int gjatrreshti = 0;
int gjatmors = 0;
*/
char *input;
int germa;
char *kodimors;
int cilen = 0;
if (argc > 2) {
printf("argumenti i vetem eshte -m\n");
return -1;
}
if (argc == 2) {
if ( !strcmp(argv[1], "-m") )
cilen = 1;
}
input = (char*)malloc(sizeof(char)*GJAT_RRESHTI);
if (cilen) {
#ifdef DEBUG
printf("main: cilen = 1\n");
#endif
while (1) {
scanf("%s",input);
if ( strlen(input) >= 80) {
printf("nje rresht nuk mund te kete me shume se 80 karaktere\n");
return -1;
}
#ifdef DEBUG
printf("main: input = %s\n",input);
#endif
kodimors = strtok((char*)input," ");
while (kodimors != NULL) {
#ifdef DEBUG
printf("main: pas While(kodimors); kodimors=\"%s\"\n",kodimors);
#endif
if ( (germa = morsshkronje(kodimors)) != -1 )
printf("%c",germa);
else
printf("gabim ne hyrje input=%s\n", (char*)input);
kodimors = strtok(NULL, " ");
}
}
} else {
#ifdef DEBUG
printf("main: jem tek shkronja mors\n");
#endif
while ( (germa = fgetc(stdin)) != 0 && germa != '.') {
#ifdef DEBUG
printf("main: jem tek shkronja mors+while\n");
#endif
if (germa == ' ' || germa == '/' || germa == '\\' || germa == '\n' || germa == '\t')
{}else {
if (germa >= 'a' && germa <= 'z')
germa = toupper(germa);
#ifdef DEBUG
printf("%c\n",germa);
#endif
if ( (kodimors = shkronjemors(germa) ) != NULL)
printf("%s ", kodimors);
else {
printf("main: Karakter qe s'ben pjese ne kodin mors: (%c)\n",germa);
return -1;
}
}
} /*end while*/
}
return 0;
} /* fund main() */
Krijoni Kontakt