Hey guys,
I am trying to implement the following but the compiler is not liking it. What can I do to fix this?
Thanks for any help.

typedef struct
{
       int ordinalSum;
       int LexemeCode;
       Line Info;
       Node *next;  <-- ???
}Node;

error # 1 syntax error before "Node"

The compiler doesn't recognize Node until after the typedef has been fully parsed. So you can't use the typedef inside the struct. In order to write a recursive struct, you'll need to name your struct without typedef and use that name in the struct.

struct node {
    struct node* next;
};

You can still typedef it if you want, but you'll only be able to use the typedefed name outside of the struct - inside the struct you need to use the struct name.

c:2:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
truct
^~~~~
c:2:6: error: expected ';' after top level declarator
truct

I hope this helped

commented: Not related to any code posted in this thread. +0

Cproger, could you please clarify what you're trying to say? You've posted an error message that one might get if one misspelled struct as truct. However no one misspelled struct that way in this thread. So I'm not really sure how your post relates to this thread.

Im saying that on line 21 you have an error that defults 'int'.

int' [-Wimplicit-int]
truct

You also have another erroewith an unexpected ';'.

';'

I hope thats more clear.

commented: Completely and utterly false -1

None of the code snippets posted in this thread even have a line 21. Certainly none of them have any errors like the ones you're talking about. It seems like you're just saying stuff at random.

im not saying random stuff, I put this code in my terminal, and it said that there are errors. You are right about the line 23, but that was the programs problem. I'm sorry about the mistakes.

Oh sorry i dinn't mean 21, i meant 2.1 sorry. :(

Look I'm not saying anything bad?

Look I'm not saying anything bad?

Yes, you are. First of all nothing you've said is helpful and adding to a thread without adding value is bad because it revives the thread without reason - especially when a correct answer has already been given.

Secondly your advice in this thread was actively harmful in that it has nothing to do with the OP's problem and would only cause him to look for his problem in the wrong place if here were to take it seriously.

Look I'm not saying anything bad?

You're not saying anything bad, you're just completely wrong. I suspect that the errors you're getting are due to how you're copying and compiling the code, not anything with the code itself, which is just a snippet and contains exactly one error on the stated 6th line. The problem is that the typedef is incomplete at the point where next is defined, and thus it cannot be used. The solution is to give the structure a proper tag and use that:

typedef struct Node
{
       int ordinalSum;
       int LexemeCode;
       Line Info;
       struct Node *next;
}Node;

Structure tags and typedef identifiers are in different name spaces, so they can both be Node. Easy peasy, but it's still a snippet, so you'll get errors if you try to compile it as if it were a complete program.

I am not wrong! I put this program in my terminal, and it showed the errors! So what I am saying is that you are right and I am also right

I am not wrong! I put this program in my terminal, and it showed the errors!

Let me be more clear in what I mean by "you're wrong". You're wrong in that what you said to help the OP was wrong in every conceivable way. I have no doubt that you're getting errors on your "terminal", but I also have no doubt that it's because you're at a point in your own education where you have no business trying to help others.

My advice to you is learn before trying to teach.

I have proof that I got these form my terminal.

You know what. I am leaving this website. 2 days ago I started to be part of this website but now you are mean to me with your bad attitude. I was just trying to help a little. I can't belive how poeple like you. I'll tell all my classmates to never go on this website and always say bad things to deceptikon. So goodbye and I am happy I will never ever hear your stupid attitude again!

Member Avatar for Mouche

I know this thread is over, but I need to point this out for the sake of Daniweb.

deceptikon and sepp2k: cproger obviously posted to help. His first post was only a week after the original, so it wasn't really reviving a zombie thread. The poster hadn't responded yet, so it's not that unnecessary to try to help out.

Then yeah, he probably copied and pasted the code wrong, yielding a bad error. Or he's using some odd compiler that gave different output. And when he analyzed the error, he read 21 instead of 2:1. After a couple posts, he explained how he got his output.

So, you're dealing with someone that is not too experienced in debugging this kind of thing, but using language like "It seems like you're just saying stuff at random", "wrong in every conceivable way" (bolded, even) and "you have no business trying to help others" doesn't really help him out and makes it seem like you're attacking him.

Unless you do want to discourage beginner/intermediate programmers to try to help out, I think you might want to take a more patient approach to dealing with them.

commented: thank you for explaining +1

cproger obviously posted to help.

That's not obvious at all. If it was just an accident that he mispasted the code in this question, then why did he do the same thing (posting an error message that was not caused by the code in the thread) in every other thread he responded to? He can't be that bad at copy and pasting. Why did he post a link to w3schools in a thread that had nothing to do with the web? Because he's such a newbie that he can't tell the difference between HTML and C++?

No, because he's a troll who gets a kick out of people responding to him and trying to correct him. And maybe as an experiment to see how many people he can get to believe that he's acting in good faith.

commented: Be quiet for once please +0

Unless you do want to discourage beginner/intermediate programmers to try to help out, I think you might want to take a more patient approach to dealing with them.

In the case of beginners who know close to nothing, won't admit that they know close to nothing, and stubbornly insist that they're neither wrong not clueless, I'd prefer that they didn't help until they have a bit more experience.

You'll notice that the vast majority of beginners who try to help are encouraged. So maybe you should consider why we were giving this one such a hard time. Be sure to read all of his posts for a complete perspective.

This is what I have done to solve it. I found an example similar to this in a text book on books24x7

typedef struct Node
{
       int ordinalSum;
       int LexemeCode;
       Line Info;
       struct Node *next;  
}Node;

I appreciate all the replies, and would like to applogize for the late appreciation. It is just that I got busy with all this coding.
Thanks
Alex

I am a begginer and I am trying to learn. But if you guys give me a hard time I can't learn. If you want to be an idiot and a maniac and give people hard tims go to another website and post stuff there. LaMouche is right.

One more thing deceptikon.

HOW THE HELL ARE YOU AN ADMIN!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.