I want to make a C program that will print morse code but I am having a trouble returning the value of Y to the main function, so that later I can use that value of Y to compare it with the another base string to print the answer. I also have a doubt, please clarify if you know the answer. If I make my length parameter global does the value of the input length from the main function get stored in that parameter? thanks in advance
int length;
int *callfunction(int x){
int temp=x;
int Y;
static int r[1000];
if(temp==0 || temp==1){
Y=1; // for a
}
else if(temp==2 || temp==3){
Y=2; //for b
}
else if(temp==4 || temp==5){
Y=3; //for c
}
else if(temp==6 || temp==7){
Y=4; // for d
}
for(int i =0;i<length;i++){
r[i]=Y;
}
return r;
}
int main(){
int i,j,k,*p[1000];
char string[100];
char string1[]={'A','a','B','b','C','c','D','d'};
const char* string2[]={"•-","-•••", "-•-•","-••"};
printf("Enter a string:");
gets(string);
printf("The entered string is:%s\n",string);
length= strlen(string);
printf("Length=%d\n",length);
for(j=0;j<length;j++){
for(i=0;i<8;i++)
if(string1[i]==string[j]){
p[i] = callfunction(i);
}
}
for(i=0;i<length;i++){
printf("%d",p[i]); //I want display the Y number here
printf("\n");
}
getchar();
return 0;
}
The program executes without any errors but I don't get the actual value of Y when the execution is done, please help