I am writing a program to reverse a string without using string functions available from standard library.
Following code is giving me some error when compiling
#include<stdio.h>
int main ()
{
int i,j;
char *p,*s,*g;
p="abcdefgt";
i=0;j=0;
s=NULL;
g=NULL;
while (p[i] != '\0')
{
printf(" %d %c\n",i,p[i]);
i++;
}
i--;
// printf("\n outside while loop i=%d",i);
while (i>=0){
// printf("\n in while p[i]=%c s[%d]=%c\n",p[i],j,s[j]);
s[j]=p[i];
j++;
i--;
printf("\n j=%d i=%d",j,i);
}
printf(" %s\n",s);
}
I used gdb and found the error in above code was coming in
s[j]=p[i];
Why is that error coming?