[C]What's wrong with this string reverser function

Hi! I'm kinda new to C but not new to Programming in general. I'm trying to right a function to reverse a string, but I have no idea why it's not working. For example I would enter "hello" when it prompts to enter a phrase, and would get the output "hhhhhh". I have no idea what's wrong Help me obi wan kano/g/


#include
#include

char * reverse(char phraseToReverse[]);

int main(){
printf("Enter string to be reversed: ");
char phrase[999] = "";

gets(phrase);

//char reversedPhraseFinal[] = reverse(phrase);

reverse(phrase);

return 0;
}

char * reverse(char phraseToReverse[]){
char reversedPhrase[999];

int phraseLength = strlen(phraseToReverse);

for(int i = phraseLength; i >= 0; i--){
for(int p = 0; p

#include
#include
#define CHAR_STD_SIZE 257
void stringReverse(char *str)
{
int length = strlen(str);
for(register int x = 0,y = (length-1);x

I thought it couldn't get any more hideous after OP's post but thanks again for proving me wrong, Sup Forums!

And what's so hideous about it, dipshit?

Your loop iterates through reversedPhrase for every letter in phraseToReverse. In your example, reversedPhrase becomes "ooooo", then "lllll", and on until it becomes "hhhhh"

If you are gonna put it in a new string (reversedPhrase) you dont need two loops. The last loop will just set everything to h, in your example.
Your code is shit and full of mistakes you lack the basics newfriend.

Your problem is that you have two loops, one inside another.
The string hello has 5 characters, so to reverse it you nee 5 iterations.
Instead you iterate 25: for i=4 you iterate 5 times, for i=3 you iterate 5 times, etc... (ignoring off-by-one errors).
Instead of the second for loop you should just have int p=phraseLength-1-i.

Indentation, for one. Wait, that wasn't a troll post? You actually thought that would be a good contribution?

>Indentation, for one
That it? Kill yourself, nitpicking faggot. If you've been here longer than one day you'd know 4chins botches up formatting.

Doesn't for me. And I've been here for a looooooooong time.

>for one
>That it?

No, that not it.

>Doesn't for me
>works on my machine
>No, that not it.
What else is there, shitbag?

We're still on formatting. Sup Forums does not fuck it up. When you admit that you can't use a browser and/or a text editor property, I will continue.

#define CHAR_STD_SIZE 257
void stringReverse(char *str){
int length = strlen(str);
for(register int x = 0,y = (length-1);x

>i have no other complaints about the code, so I'll just keep yapping about formatting which is irrelevant
Kill yourself, nitpicking faggot. I won't admit Sup Forums not fucking up because it fucks up formatting when you copy paste code, but whatever I do, it won't calm down your autism since you'll claim I fucked with the indentation in my editor.

I won't claim anything but the simple fact that you made a post with broken formatting through no fault but your own. The more you deny the truth the more silly you look.

#include
#include
#define CHAR_STD_SIZE 257
void stringReverse(char *str)
{
int length = strlen(str);
for(register int x = 0,y = (length-1);x

Here's the webm, faggot. Get rekt.

user. I do not care in the slightest how you managed to fuck up. What matters is that you did fuck up. Look at this post: . It's your code with proper formatting. Sup Forums does allow you to post properly formatted code.

Whatever it is you think I need to do to get proper formatting is beside the point, because I copy pasted the code exactly as it appeared in my text editor and the text window in app chan with video proofs. So go fuck yourself.

Also
>curly braces not on next lines
>proper formatting
Hearty chuckle.

''.join(list (reversed(string)))

Go home c babbies

Proof of what? The proof that you fucked up is in this thread - it's your post. You can't turn broken formatting into proper formatting by posting a video of how you wrote it.

>curly braces on next lines

disgusting.

void my_function(char const* arg) {
...
}


...much better.

void reverse_string ( char *string )
{
size_t length = 0;
while ( string[ ++length ] != 0 )
;
char c;
for ( int i = 0; i < length / 2; ++i ) {
c = string[ length - i - 1 ];
string[ length - i - 1 ] = string[ i ];
string[ i ] = c;
}
}

>You can't turn broken formatting into proper formatting by posting a video of how you wrote it
Goddamn moron, I copy pasted the code exactly as it appeared to me. Are you brain dead so you can't put two and two together and figure out that that the text got fucked up on the Sup Forums side and not mine? Again whatever you think I need to do in order to get proper formatting including typing the text in the window by hand or deleting whitespace is beside the point.

what? are you fucking serious?

What do you mean?