In: Computer Science
. Use a validation loop to prompt for and get from the user a string that is up to ten characters in length. Create value function encodedString that takes the string as input and returns the equivalent encoded string. Start with an empty encoded string. Use a for loop to encode each character of the input string. Use the following algorithm to encode a character and append the encoded character to the encoded string:
#include <stdio.h>
#include<string.h>
char result[10]; //to store the final result
char *encodedString(char str[]); //defining the function
int main()
{
char string[10], i;
for( i = 0 ; i < 10 ; i++)
{
scanf ("%c", &string[i]) ; //taking input
}
char *res = encodedString(string); //calling the function
printf("%s",res); //displaying the output
}
char *encodedString(char str[])
{
char i;
for( i=0; i<10; i++)
{
result[i]=str[i]+1; //encodes by making a->b, b->c and so on
i.e converting to ascii and adding 1
}
return result;
}