#String reverse assignment

8 messages · Page 1 of 1 (latest)

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

int main() {
    char odd_string[10] = { '0', '1', '2', '3', '4', '5', '6', '7', '8'};
    char even_string[10] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
    char empty_string[10];
    char single_char[10] = {'0'};

    for (int i = 0; i < strlen(odd_string); i++) {
    if odd_string[i] != Nan

        odd_string[i] = odd_string[strlen(odd_string) - i]
    }
}```
halcyon locustBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

jade lantern
#

im not done building it but i wanted to know, how do we tell whether a place in a char array is not initialized

#

like if i actually put a value in it

#

nvm dont answer this i shall come back with more thought put into it

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

int main() {
    char odd_string[10] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '\0'};
    //char even_string[10] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
    //empty_string[10];
    //char single_char[10] = {'0'};

    int i;
    for (i = 0; i < strlen(odd_string); i++) {
        if (odd_string[i] > 0) { // 0 = null so im assuming it should work
            char replacer = odd_string[i];
            char replaced = odd_string[strlen(odd_string) - i];

            odd_string[i] = replaced;
            odd_string[strlen(odd_string) - i] = replacer;

            printf("%s\n", odd_string);


        }
    }
}```
#

i ended cheating 😦 a lil but here is the solution i got

#

!solved