On Thu, 20 Sep 2001, Logu wrote:

> 
> > > #include<stdio.h>
> > > #include<string.h>
> > > int main(void){
> > >   char *pass="logu";
> > >   char *s;
> > >   int i;
> > > 
> > >   printf("Enter the passwd: ");
> > >   scanf("%s",s);
> >                ^^
> > 
> > Where have you malloc'd? You need to allocate memory
> > for s.
> If remove that "int i;" statement it works without any problem.

Purely coincidental. If the string you read with scanf is long enough, you
will get a segfault too.


Don't know you specific intentions, but using pointers without allocating
storage for them to point to will give you all sorts of headaches (as you
recently experienced with the above program).

My suggestion is to get yourself a book on C programming. It would be good
to have the book explain pointers in depth too.

For example, Pointers in C by Yashwant Kanetkar was a good one (probably a
bit dated but nonetheless relevant).

-Naren



_______________________________________________
linux-india-help mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/linux-india-help

Reply via email to