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);
>
> }
You declared the variable string to be of type char, which means string
will hold 1 character. Any more than that will overwrite memory and give
you an segmentation fault. Declare string to be an array of characters
like this:
char string[81];
Now string is a pointer to the beginning of an array of characters. The
array is large enough to hole 80 characters and 1 Null character at the
end to terminate the string.
Look also at this:
char *string;
Then use malloc() to allocate enough space to hold the length of string
you require.
--
Danial Micheal Howard : [EMAIL PROTECTED] : (208) 282-3097
IT Programmer/Analyst Associate
Computing and Communications, Idaho State University
_______________________________________________
Seawolf-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/seawolf-list