Answer the question
In order to leave comments, you need to log in
Why doesn't it reverse the string?
Good evening! Help me understand what the error is ...
There is such a code:
#include <stdio.h>
#include <string.h>
char *ft_strrev(char *str)
{
char tmp;
int start_len;
int end_len;
start_len = 0;
end_len = 0;
while (str[end_len])
end_len++;
end_len -= 1;
while (start_len <= end_len)
{
tmp = str[end_len];
str[end_len] = str[start_len];
str[start_len] = tmp;
start_len++;
end_len--;
}
return (str);
}
int main(void)
{
char *str = "hello";
ft_strrev(str);
printf("%s", str);
return (0);
}
str[end_len] = str[start_len];
Answer the question
In order to leave comments, you need to log in
What's wrong?
char *str = "hello";
char str[] = "hello";
#include <iostream>
#include <string>
#include <algorithm>
int main()
{
std::string str = "test string";
std::reverse(str.begin(), str.end());
std::cout << str << std::endl;
return 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question