change to this: scanf("%s", &string);
You have to pass your variable by reference with scanf or else it'll seg
fault. Also, be careful of using "string" as a variable. There are some
string libraries out there which already use it. You _could_ end up with
problems in some cases when using the symbol name. :)
On Fri, 14 Dec 2001, Antti Hakulinen wrote:
> Hi there.
> I just started to learn C, and this evening i did the following simple
> program:
>
> #include <stdio.h>
>
> int main()
> {
> char string;
> printf ("Enter something:");
> scanf("%s", string);
> printf ("You entered %s\n", string);
>
> }
>
> After i compile it, and i run it, it gives me segmentation fault and core
> dump occurs naturally. Core doesn't reveal anything useful, atleast for me.
> So, is the gcc buggy or where the problem could be with this simple code.? I
> believe the code is right...
> How to trace these kindaof problems properly?
> Any similar experiences any1?
>
> Regards: Antti
> ###########################################
>
> This message has been scanned by F-Secure Anti-Virus for Microsoft Exchange.
>
>
>
> _______________________________________________
> Seawolf-list mailing list
> [EMAIL PROTECTED]
> https://listman.redhat.com/mailman/listinfo/seawolf-list
>
--
-Statux
_______________________________________________
Seawolf-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/seawolf-list