ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Here's your problem. The C string literal "linux" actually has six characters in it: the five you can read plus the null character \0 (value of zero) which indicates the end of all C strings.
This causes your string literal to go outside the bounds of the array you're assigning it into (six bytes for five slots).
Edit: Sorry; looks like I'm a slower typist than Spooon.
Last edited by taylor_venable; 06-23-2006 at 08:17 PM.
Hmm, yes; looking closer, I see what might be a few more problems. Normally, the main method's signature is expressed as
Code:
int main(int argc, char** argv)
or
int main(int argc, char* argv[])
I'm also unsure about the meaning of the star (*) in front of strcpy(). While I'm certain that writing out of array bounds will (or rather, should) cause a segmentation fault, xhi is also correct. Passing argv[1] as "somethingverylong", or any string more than four characters, would cause the same problem. That's why you should normally use something at least as secure as strncpy() when dealing with possibly untrustworthy input.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.