#include<iostream.h>
#include<stdlib.h>
using namespace std;
char* Gets(char *s)
{
char ch,*p;
p=s;
while ( (ch=getchar()) != '0' )
{
*s=ch;
s++;
}
s='\0';
return p; //return the address of S stored in P.
}
int main(int argc,char* argv[])
{
//char s[200];
char *s;
s=Gets(s);
cout<<"\n After Gets Value of S=["<<s<<"] \n";
return 0;
}
If I use char *s
I am getting the output as
Segmentation fault:11
If I use char s[200]
there is no error. Why am I getting segmentation fault?
– chux - Reinstate Monica Aug 30 '16 at 02:40