Write a C program coding that includes a main program and tw
Solution
#include \"stdio.h\"
#include \"string.h\"
typedef struct{
char from[28];
char to[28];
}CodeT;
void encodeStr(char *input, char *output, CodeT code);
void decodeStr(char *input, char *output, CodeT code);
int main(void) {
// Disable stdout buffering
setvbuf(stdout, NULL, _IONBF, 0);
int i;
CodeT code ={ .from = \" abcdefghiklmnopqrstuvwxyz\",
.to = \".172093%@#+!:_-$^()854=6?>\"
};
char inp[100] = \" abcdefghiklmnopqrstuvwxyz\";
char outp[100];
encodeStr(&inp,&outp,code);
decodeStr(&outp,&inp,code);
for(i=0;i<strlen(inp);i++){
printf(\"%c\",inp[i]);
}
return 0;
}
void encodeStr(char *input, char *output, CodeT code){
int i,j;
int len = strlen(input);
// for each character in input
for(i=0;i<len;i++){
// check in each character of from in code and add to in code to output
for(j=0;j<28;j++){
if(input[i]==code.from[j]){
output[i] = code.to[j];
break;
}
}
}
}
void decodeStr(char *input, char *output, CodeT code){
int i,j;
int len = strlen(input);
for(i=0;i<len;i++){
// check in each character of from in code and add to in code to output
for(j=0;j<28;j++){
if(input[i]==code.to[j]){
output[i] = code.from[j];
break;
}
}
}
}
/* sample output
abcdefghiklmnopqrstuvwxyz
*/

