#Reversing a string
17 messages · Page 1 of 1 (latest)
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 run !howto ask.
I tried this but it's also not working
Well, you need to copy the string
If you try writing the chars to the string you are reading from, that can cause danger
For example, "abcd'
You look at last letter, it is d
So you put it in index 0 to get "dbcd"
Well when you get to the last index, you will need the 1st letter
But "a" is nowhere to be found
Here is what I would suggest
int len = strlen(str)
for (int i = 0; i < len/2; i++) {
char tmp = str[i];
str[i] = str[len-1-i];
str[len-1-i] = tmp;
}
Try smth like this
I'm not supposed to use pre-defined functions
That's why i add 1 to j everytime an element in the array doesn't evaluate to 0
for (i = 0; *(s + i); i++){
j += 1;
}
Idk what ur doing in the screenshot bc its so small but you can probably use recursion to reverse a string
also you can just make your own strlen function pretty easily and toomany's code will work for what u want
!solved