S
shya
hi there!
I just wrote a function that reverse a string. It seems all ok to me,
but the program goes on segmentation fault on *s = *t_str.
Here's the code:
#include <stdio.h>
#include <stdlib.h>
void reverse(char *s)
{
char t;
char* t_str;
for (t_str = s; *t_str != '\0'; t_str++);
t_str--;
for (; s < t_str; s++, t_str--) {
t = *s;
*s = *t_str;
*t_str = t;
}
}
int main(int argc, char *argv[])
{
char* s = "Hello world!";
reverse(s);
printf("%s", s);
return 0;
}
what's wrong??!
thanks!
I just wrote a function that reverse a string. It seems all ok to me,
but the program goes on segmentation fault on *s = *t_str.
Here's the code:
#include <stdio.h>
#include <stdlib.h>
void reverse(char *s)
{
char t;
char* t_str;
for (t_str = s; *t_str != '\0'; t_str++);
t_str--;
for (; s < t_str; s++, t_str--) {
t = *s;
*s = *t_str;
*t_str = t;
}
}
int main(int argc, char *argv[])
{
char* s = "Hello world!";
reverse(s);
printf("%s", s);
return 0;
}
what's wrong??!
thanks!