Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
You correct it by doing something else useful with the struct. Access one of its members, or get the address of the struct. One of the few things that might be useful with just n is to compare it to another "struct node", but to compare it to an integer that starts with 0 might not be what you want. Or is it? This is why my previous answer was so short.
For a lot of things in C, you can cast from one type to another, as in this:
Code:
n = (struct node *)malloc( sizeof( struct node ));
This thing would repeatedly print one tabulator character.
To make this fact more clearly visible, i would really suggest to indent the following printf-line, as this will be the only thing that would be executed as body of the for() loop.
And then, how many TAB characters do you intend to print?
You probably want to remove the for() line entirely?
Addendum: maybe "h" means "number of horizontal tabulators"? Then you should replace that "i<n" with "i<h", as "h" is not used anywhere else in the code? Anyhow, strange code snippet.
You are correct. I didn't look at the OP's code carefully enough the first time to see that.
Quote:
maybe "h" means "number of horizontal tabulators"?
h represents how many levels of the sideways tree being printed are to the left of the subtree currently being printed. It is a recursive tree printing routine. That is what I didn't pay attention to the first time. So for the actual printing at each level (the part other than the recursion), you need h tabs to the left of the text.
yeah I did change the "n" to "h" only in i<n and no, it does not give the same warning.
when I replace n with h, I get this - "warning: assignment from incompatible pointer type [enabled by default] "
Thank you all for your help!
The warning is removed. yes, all i had to do was to replace "n" with "h". When i replaced it last time, I'd made a typing mistake elsewhere. Thats's why i got a warning.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.