Reverse string
#1

Код:
Function:Reverse(string[])
{
	new string1[256];
	for(new i = 0, j = strlen(string); i < strlen(string); i++, j--)
	{
	    string1[i] = string[j];
	}
	return string1;
}
So I made this function, but it won't print anything on the screen or return anything

Function is just a macro I've made.
Reply
#2

Try this,

How are you calling Reverse and what is it being passed?

PHP код:
Function:Reverse(string[])
{
         
// Setting vars
    
new string1[256];
               
lengthOfString strlen(string);
        
// Processing 
    
for(new 0strlen(string); i++)
    {
        
string1[i] = string[(lengthOfString-i)];
    }
        
// Returning processed string
    
return string1;

Reply
#3

Код:
printf("%s", Reverse("Teeeeeeeeeext"));
Thank you, I always seem to forget that strlen returns even the '\0' part, so I didn't add -1
now it works, thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)