+ 1
What is the problem in my code ?
It's giving no output. https://code.sololearn.com/c0QXh4X3WgpJ/?ref=app
6 Respuestas
+ 2
Check for three characters it is giving correct result but for 4 variables it gets changed
+ 1
Solved :--
#include <stdio.h>
int main() {
void reverse(char *); // prototype declaration locally.
char str[100];
printf ("Enter the string: ");
scanf("%s",&str);
reverse(str);
printf("The reverse string is %s",str);
return 0;
}
void reverse(char *str)
{
int i,j;
char *s,*beg,*end;
for(i=0; *(str+i)!='\0'; i++); // i counts the length of the string str.
beg=str; //initially start of string
end=str;
//pointer moved to last character
for(j=i-1;j>0;j--)
end++;
//swaping and updating value
for (j=i-1; j>0; j--)
{
s=*end;
*end=*beg;
*beg=s;
beg++; end--;
}
}
+ 1
#include <stdio.h>
int main() {
char *reverse(char *); // prototype declaration locally.
char str[100];
printf ("Enter the string: ");
scanf("%s",&str);
reverse(str);
printf("The reverse string is %s",str);
return 0;
}
char *reverse(char *str)
{
int i,j;
char *s,*beg,*end;
for(i=0; *(str+i)!='\0'; i++); // i counts the length of the string str.
beg=str; //initially start of string
end=str;
//pointer moved to last character
for(j=i-1;j>0;j--)
end++;
//swaping and updating value
for (j=i-1; j>0; j--)
{
s=*end;
*end=*beg;
*beg=s;
beg++; end--;
}
return (&s);
}
+ 1
Check again, this is what you wanted.
0
The problem is almost solved.
I'll post the final answer soon.
- 1
I think some logical errors I will solve it