--- Naren Devaiah <[EMAIL PROTECTED]> wrote:
>
> 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).
I'd also suggest
http://www.eskimo.com/~scs/C-faq/top.html (The
comp.lang.c FAQ). Absolutely cool! You can also ftp
the full thing if you don't want to surf so much.
Prashant
____________________________________________________________
Do You Yahoo!?
Send a newsletter, share photos & files, conduct polls, organize chat events. Visit
http://in.groups.yahoo.com
_______________________________________________
linux-india-help mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/linux-india-help