I made the strrev function myself. While compling it says that the code in the func xstrrev() has no effect. I would also like to know that while making a copy of the built in function for assignments can we use builtinfunctions(other) in it? As I used strlen() in it.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void xstrrev(char str[]);
void main(void)
{
char str[30];
printf("Enter a string:");
gets(str);
xstrrev(str);
printf("\n%s",str);
getch();
}
void xstrrev(char str[])
{
int i,x;
x=strlen(str);
for(i=0;;i++)
{
if(str[i]=='\0')
{
break;
}
str[x-i]=str[i];
}
}
You used the comparison operator
==instead of the assignment operator=.So the compiler is right: xstrrev just executes a comparison, whose results are ignored, not an assignment.
As for your second question, this is not the right forum to ask it, only your teacher can tell what is allowed and what is not. However implementing
strlenis exactly two lines of code.