What the hell is happening here?

What the hell is happening here?
Why is h changing to p?

Attached: trim.png (721x722, 46.8K)

Nigeria

why don't you step through the dubugger you retard and see why

Explain.

Fuck you bitch, I don't know how to use the debugger, explain it.

No. Learn to use the debugger.

maybe its time to learn and stop being a useless nigger.

You are actually the useless one.
If someone asks a question, you don't tell them to go somewhere else your mentally braindead retard. Learning is exactly what I am doing right now you faggot, this is impossible to learn without outside guidance, this is a retard system built by retards like you, so either explain it or shut the fuck up you worthless sack of shit.

char s2[i3];

kys

Nothing wrong with that you fucking idiot, you don't know shit so shut the fuck up.

>learning is what I am doing right now
>NO I REFUSE TO USE THE TOOL DESIGNED EXACTLY TO TELL ME HOW TO SEE WHAT IS HAPPENING

google "how to use "

Somebody should ban this faggot everytime he posts, you are such a bitch.

post the code as text if you want help

#include
main()
{
char string[] = {' ','h','e','l','l','o',' ',' ','\0'};
printf("%s\n",trim(string));
}


* trim(char s1[])
{
int i1 = 0; //char array index
int i2 = 0; //start index
int i3 = 0; //word indicator
int i4 = 0; //end cut measure
while(s1[i1] != '\0')
{
if(s1[i1] == ' ' || s1[i1] == '\t' || s1[i1] == '\n')
{
i3 = 0;
i4++;
}
else
{
if(i2 == 0)
{
i2 = i1;
}
i3 = 1;
i4 = 0;
}
i1++;
}
i1 = i1 - i4; //end
i3 = i2 - i1 + 1; //length
i4 = 0; //newIndex
char s2[i3];
while(i2 < i1)
{
s2[i4] = s1[i2];
printf("s2:%c, s1:%c\n",s2[i4],s1[i2]);
i2++;
i4++;
}
return s2;
}

cool memory management, ahmed

Among other things, you calculate i3 as -4 and you return an array allocated on stack (s2) which is a clear mistake. It doesn't output s2:p for me, it outputs s2:h even with your broken code. I got it to work fully after fixing the two errors I mentioned above.

>not wasting time on this crap
learn to debug faggot

Omg thank you.

As to why it might be printing p, one possibility is with your i3 calculated as -1, s2[i4] = s1[i2]; line could actually be modifying s2, not the data inside that array, but the actual pointer in memory. So after that assignment that points to some random place in memory, and contents at that address happen to be p. After that there is no modifying of the pointer, so all assignments work as they should.

Cleanup your code and maybe someone will be able to read it.

Yep needs to be
#include
main()
{
char string[] = {' ','h','e','l','l','o',' ',' ','\0'};
printf("%s\n",trim(string));
}


* trim(char s1[])
{
int i1 = 0; //char array index
int i2 = 0; //start index
int i3 = 0; //word indicator
int i4 = 0; //end cut measure
while(s1[i1] != '\0')
{
if(s1[i1] == ' ' || s1[i1] == '\t' || s1[i1] == '\n')
{
i3 = 0;
i4++;
}
else
{
if(i2 == 0)
{
i2 = i1;
}
i3 = 1;
i4 = 0;
}
i1++;
}
i1 = i1 - i4; //end
i3 = i1 - i2 + 1; //length
i4 = 0; //newIndex
char s2[i3];
while(i2 < i1)
{
s2[i4] = s1[i2];
printf("s2:%c, s1:%c\n",s2[i4],s1[i2]);
i2++;
i4++;
}
return s2;
}

After line 35, values of indices are:
i1 = 6
i2 = 1
i3 = -4
i4 = 0
Your logic is wrong. i3 shouldn't be negative.

In the while loop on line 37:
When you copy i1 to i2, you forget to copy the '\0' character.

On line 9:
What the fuck is return type *? It should be char *

And so on...

Take it slow. Do it step by step. You've gone wayyyyy ahead of yourself with this program.

Learn to step through your code by hand. Using a debugger comes after that.

Now fuck off and study.

>Omg
*vomit*

People like OP is the reason why Rust exists.

I'm pretty sure OP isn't a tranny.

>I'm pretty sure OP isn't a tranny.
Nice try, OP.