Why this program doesnot gives reverse of the given string computer, though the length() function works fine(when I comment other codes and only run that part) and gives output correct but the second reverse() function is not giving any output.
#include <stdio.h>
#include <string.h>
int length(char *);
char *reverse(char *, int);
int main()
{
char word[] = "COMPUTER";
int count;
count = length("COMPUTER");
printf("%s", reverse(word, count));
}
int length(char *p)
{
int count;
for (count = 0; *(p + count) != '\0'; count++);
return (count);
}
char *reverse(char *p, int count)
{
char temp;
for (int i = 0; i < count / 2; i++)
{
temp = *(p + i);
*(p + i) = *(p - (count - 1) - i);
*(p - (count - 1) - i) = temp;
}
return (p);
}