[Solved] Сhanging even and odd characters in a string array


Without code we can’t really help you fix it… but here is a solution:

#include <stdio.h>
#include <string.h>

int main()
{
    char str[11] = "HelloWorld";

    for(int i = 0; i < strlen(str); i += 2)
    {
        char tmp = str[i];
        str[i] = str[i+1];
        str[i+1] = tmp;
    }

    printf("%s", str);
    return 0;
}

Output: eHllWorodl

Save the current character in a temporary variable, replace it with the next one.

1

solved Сhanging even and odd characters in a string array