ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I understand why im getting the other error its because the value im passing to the function
is not const in the main program but of course that is the point. So my next question would be if i dont want the function to be able to modify the information in the array that i pass
but beable to access its contents how would i be able to do this without generating an error
normally i would ignore the error but i dont want gcc to compile it not as constant cause
that would defeet the purpose.
by the way is this a good idea for security of functions or is this just a supid step that
is no longer used or needed with functions in c programminig
I'm going to jump back to the array initialize question real quick.... I'd use memset instead to initialize. Look at the man page to get the full description... but I think something like "memset(deck,0,4*13*sizeof(int *));" would work well for you.
As for the const problem... cast the array as const when you pass it into the function.
Non-const variables are automatically promoted to const when passed as arguments to functions expecting const types. No cast necessary and no warning should be generated. If's getting a warning it's due to some other mistake. And warnings regarding pointers are often not harmless as warnings can be.
Originally posted by itsme86 Close, but you want to use sizeof(int) instead of sizeof(int *). Yours will probably work accidentally though since an int is the same size as a pointer in most environments.
Ya... that was a typo on my part... hope it didn't cause any problems.
yea sorry i was looking at something called shuffle in my book and posting about the warning at the same time.
i normally dont make arrays static tho because they are passed by refrence to functions anyway. unless of course
the array is declared in the function and i want to retain the values after the function exits.
i however dont understand your use of static here.
static as far as i have been told just means that the data will not be destoyed after a function exits.
When I said statically allocated I simply mean allocated on the stack as opposed to allocated on the heap, which is done, as I'm sure you know, by calling malloc(). Anyway, if you just want to print the two-dimensional array you can pass it to a function like I'm doing in shuffle() or shuffle2(). shuffle2() is a bit more complicated but as a bonus you don't have to specify any boundaries when declaring it. Make the parameter const if it's not supposed to be altered (I always do that).