i need to write a function which inputs a string
and removes all the spaces from the start and removes all the spaces from the end of the string.
the string consists of words separated by spaces.
if between two words we have more then one space ,it cuts down the excess spaces
til its left with one space only between two words.
and each char is flipped to its parallel ascii value "c" to "x" , "i" to "h" etc..
for example:
" C is wonderful "
turn to
"X hr ofuivwmld"
i tried to solve it like this
Code:
char* AtBash(char* text)
{
int i=0,start,j=0,k;
char* word,*str,c;
str=text;
while (i<strlen(text))
{
for(i=0;str[i]!=' ';i++);
if (i<strlen(text))
{
start=str;
for(j=0;((i<strlen(word)-1)&&str!=NULL;i++)
word[i-start]=text[i];
strcopy(word,word+1);
for (k=0;k<strlen(word);k++)
{
c=word[k];
if(c>'Z')
str[j]=c-26+'A';
else
str[j]=c-26+'a';
j++;
}
str[j]=' ';
}
srt[j-1]='\0';
return str;
}