Answer to Question #210900 in C for genji 4

Question #210900

Design a C program to reverse a string but the special characters must be in same location only the character must be reversed.


1
Expert's answer
2021-06-29T00:13:01-0400
int CheckIfAlphabet(char c)
{
    return ( (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') );
}
 
void ReverseString(char s[])
{
    int k, l = 0;
    char temp;
    k = strlen(s) - 1;
    while (l < k)
    {
        if (!CheckIfAlphabet(s[l]))            l++;
        else if(!CheckIfAlphabet(s[k]))        k--;
        else 
        {
            temp = s[l];
            s[l]=s[k];
			s[k]=temp;
            l++;
            k--;
        }
    }
}
 
int main()
{
    char str[] = "a&b#c$d*e@f";
    int n;
    printf("\nInpuyt String: ");
    for(n=0;n<strlen(str);n++) printf("%c ",str[n]);
    ReverseString(str);
    printf("\n\nOutput String: ");
    for(n=0;n<strlen(str);n++) printf("%c ",str[n]);
    return 0;
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS