this expression is incorrect:
char *str[41];
you declare 41 uninitialized strings. Do you want to:
char str[41];
then scanf("%40s" , str); , no & and limit input size (security)
then the loop (where your while (str[i]<41) is wrong, it probably ends right away, since the letters begin with 65 (the ascii code is for "A"). You wanted to test i against 41, but the str[i] test str[i] t27>, otherwise you will get all the garbage after the nul-term char in one of the odd lines or even if the line length is not 40 bytes)
while (str[i]) { if (i % 2 == 0) { odd[j++] = str[i]; } else { even[k++] = str[i]; } i++; }
if you want to use a pointer (assignment requirement), just define str as before:
char str[41];
scan the input value on it as indicated above, then indicate on it:
char *p = str;
And now that you have pointed to the buffer pointer, if you want to use reverence instead of accessing the index, you can do:
while (*p) { // test end of string termination if (i % 2 == 0) { // if ((p-str) % 2 == 0) { would allow to get rid of i odd[j++] = *p; } else { even[k++] = *p; } p++; i++; }
(we have to increase i for an even / odd test, or we would have to test p-str parity)
aaaand the last classic mistake (thanks to the last minute comments), even and odd do not have zero completion, so the risk of getting garbage at the end when printing them you need:
even[k] = odd[j] = '\0';
(as another answer , check the concept of even and odd, the expected result can be the other way around)