473,394 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Check my code please?

OK, this is the first time I've used structs. I'm trying to create a linked
list.

Obviously most of it is missing but I'm trying to get it to compile
error-free with the struct and functions defined. Why do I get the error
"parse error before '*' token" 5 times (once for each use of list_node*)?

==================================

struct list_node {
char content[10];
struct list_node *next;
};
/* Creates a new list and returns a pointer to the first node */
list_node* create_list(void) {
return 0;
}

/* Copies a string into a new node and adds to the list in alphabetical
order. Returns int success value */
int insert(list_node*, char*) {
return 0;
}
/* Removes the first occurrence of the string parameter. Returns int success
value */
int remove(list_node*, char*) {
return 0;
}

/* Prints the list of string from first to last */
void print(list_node*) {
return;
}

/* Destroys the list, deallocates all associtaed memory. Returns int success
value */
int destroy_list(list_node*) {
return 1;
}

int main()
{
}
Nov 14 '05 #1
6 1183
Steve wrote:
OK, this is the first time I've used structs. I'm trying to create a linked
list.

Obviously most of it is missing but I'm trying to get it to compile
error-free with the struct and functions defined. Why do I get the error
"parse error before '*' token" 5 times (once for each use of list_node*)?
Because C is not C++.
struct list_node {
char content[10];
struct list_node *next;
};
This defines a type whose name is `struct list_node' ...
/* Creates a new list and returns a pointer to the first node */
list_node* create_list(void) {


.... and `list_node' is only half of the name, hence the
error message.

--
Eric Sosman
es*****@acm-dot-org.invalid
Nov 14 '05 #2

Steve wrote:
OK, this is the first time I've used structs. I'm trying to create a linked list.

Obviously most of it is missing but I'm trying to get it to compile
error-free with the struct and functions defined. Why do I get the error "parse error before '*' token" 5 times (once for each use of list_node*)?
==================================

struct list_node {
char content[10];
struct list_node *next;
};
/* Creates a new list and returns a pointer to the first node */
list_node* create_list(void) {
return 0;
}


use "struct list_node*" instead of "list_node*"

Nov 14 '05 #3
Steve <st***@hello.com> wrote:
Why do I get the error "parse error before '*' token" 5 times (once
for each use of list_node*)?

==================================

struct list_node {
char content[10];
struct list_node *next;
};
/* Creates a new list and returns a pointer to the first node */
list_node* create_list(void) {
return 0;
}

[snip]


Because 'listnode*' is invalid: either use a typedef, or try
'struct listnode *create_list(void) { /* ... */ }'

--
With sufficient thrust, pigs fly just fine. However, this is
not necessarily a good idea. It is hard to be sure where they
are going to land, and it could be dangerous sitting under them
as they fly overhead. -- RFC 1925
Nov 14 '05 #4
ma*******@gmail.com wrote:
Steve wrote:
OK, this is the first time I've used structs. I'm trying to
create a linked list.

Obviously most of it is missing but I'm trying to get it to
compile error-free with the struct and functions defined. Why do
I get the error "parse error before '*' token" 5 times (once for
each use of list_node*)?

==================================

struct list_node {
char content[10];
struct list_node *next;
};

/* Creates a new list and returns a pointer to the first node */
list_node* create_list(void) {
return 0;
}


use "struct list_node*" instead of "list_node*"


Or add, after the struct definition:

typedef struct list_node list_node;

You can combine this with the type declaration, as in:

typedef struct list_node {
char content[10];
struct list_node *next;
} list_node;

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #5
[on "struct list_node" vs "list_node"]

In article <42***************@yahoo.com>
CBFalconer <cb********@worldnet.att.net> wrote:
Or add, after the struct definition:

typedef struct list_node list_node;

You can combine this with the type declaration, as in:

typedef struct list_node {
char content[10];
struct list_node *next;
} list_node;


I dislike typedefs in general -- I find code using the "struct"
keyword far easier to read -- but if you are going to use typedef
here, you might as well put it in *first*, and then use it in
the structure definition:

typedef struct list_node LIST_NODE;

struct list_node {
char content[10];
LIST_NODE *next; /* can use the typedef here, now */
};

Note that, if you do use typedefs, spelling typedef'ed names in
ALL_CAPS or UsingFunkyCapitalization or with some other special
distinguishing characteristic -- POSIX uses an "_t" suffix, for
instance -- is generally a good idea. (Otherwise it is impossible
to tell at a glance whether something is a typedef, and because
typedefs do not quite work right syntactically, it is often important
to distinguish them, to avoid name collisions.)

(Consider:

typedef int x;
void f(x x) { ... }

which is legal but horrible C code. Yes, you can do the same with
ordinary variable names; but it is even worse when you do it with
type-aliases.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #6
On 2005-03-02, 'Steve' <st***@hello.com> wrote in comp.lang.c:
OK, this is the first time I've used structs. I'm trying to
create a linked list.
<snip>
/* Copies a string into a new node and adds to the list in
alphabetical order. Returns int success value */
int insert(list_node*, char*) {
return 0;
}


In addition to what others have said, you have unnamed parameters
in many of your function definitions. This is okay for function
declarations such as (assuming a list_node typedef):

int insert( list_node *, char * );

which generally appear near the beginning of a file. But you
have to name the parameters when you write the code for the
function later:

int insert( list_node *head, char *str ){
...
}
Brandan L.
--
bclennox \at eos \dot ncsu \dot edu
Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mohammed Mazid | last post by:
Hi folks! Can anyone please help me with this? I am developing a Quiz program but I am stuck with "multiple answers". Basically I need some sort of code that would select multiple answers...
20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
8
by: kittykat | last post by:
Hi, could someone please check my code? its asking the user to enter 3 letters, and check to see if these letters exist in the text file. i know ive done something wrong. can someone fix my code...
5
by: A.Dagostino | last post by:
hi i need to update an SQL Table when user select or unselect a checkbox control. How Can i do? Thanks Alex
7
by: Tony Johnson | last post by:
Can you make a check box very big? It seems like when you drag it bigger the little check is still the same size. Thank you, *** Sent via Developersdex http://www.developersdex.com ***...
7
by: Neil | last post by:
I have a check box on a form that's bound to a function that returns a True/False value. When the user clicks on the check box, I run some code through the MouseDown event. Everything works fine. ...
1
by: scprosportsman | last post by:
Please help guys, i am trying to set up a database here at work and im fairly new to access in terms of writing functions and queries and stuff. I have 2 different places on my design that will...
8
mmarif4u
by: mmarif4u | last post by:
Hi everybody... I want to enter values to db like the following,,, Format is like this (810605-14-6356) This is the rite format, No a to z letters... 6 digits then - then 2 digits then - then 4...
1
by: icetalks | last post by:
have a look at this code , its for logging the user in after checking his UserName and Password. dim check as boolean = false ... ... If txtUserName.Text.Length = 0 And txtPass.Text.Length =...
12
by: canabatz | last post by:
i got this php file 'check.php' that checks for changes ,and showing a counter for posts !! $show_data="SELECT * FROM bidding_main WHERE bid_id='$bid_id' ";...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.