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.
It is working, just the way you want it to work is not correct
Think about it, if you allocate and assign in the first loop to index 0 then continue to the next loop and allocate and assign to index 1, what is the value at index 0?
The expression "variable++" increments the variable by one and returns the value that the variable had before incrementing. "variable--" works similarly but decrements the variable.
var - is the pointer (e.g. address of a memory location)
*var - is content of a memory pointed by "var"
*var++ - read memory location at address "var" and increment value of "var" by 1.
Let say, the initial value of "var" is 100, then "*var++" will return value stored at location 100, and increments "var" by 1, so next time location at address 101 will be read.
There are few things to point out:
Quote:
char *string = "string"
will have terminating zero at the end, because it is declared as a string, but after your program execution "var" have only six bytes of "string" without terminating zero. In other words there is a difference between these declarations:
Quote:
char string[] = "string"; /* have zero at the end */
and
char string[] = {'s', 't', 'r', 'i', 'n', 'g'}; /* no zero at the end*/
<snip>I understand what you mean, but can you show me how you would do that?</snip>
Sheesh! If you "understand" what I meant, why ask?
What I hope you understood, is that the "=" is not needed in this statement:
for(i=0; i<=6 ;i++){
<edit>
I don't think that the order of operation makes any difference in the increment of i, but, as rsasock pointed out, there is a difference between ++i and i++
</edit>
Last edited by PTrenholme; 10-05-2007 at 08:39 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.