473,385 Members | 2,028 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,385 software developers and data experts.

please check

I have written code for single linked list...I get an error as
Expression syntax in the line marked with ////////. Please correct me
where am I going wrong. I compiled this in TURBO Compiler

#include<stdio.h>
#include<alloc.h>
struct node
{
int data;
struct node *link;
};
void main()
{
int num=10;
struct node *p;
p=NULL;
append(&p,num);
getch();
}
struct node *firstnode(int num)
{
struct node *p;
p=(struct node*)malloc(sizeof(struct node));
p->data=num;
p->link=NULL;
return p;
}
append(struct node **q,int num)
{
struct node *temp,*r;
if(*q==NULL)
*q= firstnode(int); ////////////////////////////
else
{
temp=*q;
while(temp->link!=NULL)
temp=temp->link;
r=malloc(sizeof(struct node));
r->data=num;
r->link=NULL;
temp->link=r;
}
return 0;
}

Oct 16 '06 #1
10 2166
On Mon, 2006-10-16 at 06:59 -0700, raghu wrote:
I have written code for single linked list...I get an error as
Expression syntax in the line marked with ////////. Please correct me
where am I going wrong. I compiled this in TURBO Compiler

#include<stdio.h>
#include<alloc.h>
struct node
{
int data;
struct node *link;
};
<snipped similar>

Could you format and try again? From what I saw, there's a /lot/ of
problems with your code, but I'd like to be able to read it.

There's no such thing as <alloc.h>.

--
Andrew Poelstra <http://www.wpsoftware.net/projects/>

Oct 16 '06 #2
raghu wrote:
I have written code for single linked list...I get an error as
Expression syntax in the line marked with ////////. Please correct me
where am I going wrong. I compiled this in TURBO Compiler

#include<stdio.h>
#include<alloc.h>
struct node
{
int data;
struct node *link;
};
void main()
{
int num=10;
struct node *p;
p=NULL;
append(&p,num);
getch();
}
struct node *firstnode(int num)
{
struct node *p;
p=(struct node*)malloc(sizeof(struct node));
p->data=num;
p->link=NULL;
return p;
}
append(struct node **q,int num)
{
struct node *temp,*r;
if(*q==NULL)
*q= firstnode(int); ////////////////////////////
else
{
temp=*q;
while(temp->link!=NULL)
temp=temp->link;
r=malloc(sizeof(struct node));
r->data=num;
r->link=NULL;
temp->link=r;
}
return 0;
}
This is my first post to comp.lang.c, so hello to all there.

You call firstnode function with invalid parameter - 'int'. Try to
place real int parameter- variable or constant, may be 'num' that is
parameter of append() function. You now are triyng to send the type int
which is not allowed.

Oct 16 '06 #3
Andrew Poelstra <ap*******@false.sitewrites:
On Mon, 2006-10-16 at 06:59 -0700, raghu wrote:
>I have written code for single linked list...I get an error as
Expression syntax in the line marked with ////////. Please correct me
where am I going wrong. I compiled this in TURBO Compiler

#include<stdio.h>
#include<alloc.h>
struct node
{
int data;
struct node *link;
};
<snipped similar>

Could you format and try again? From what I saw, there's a /lot/ of
problems with your code, but I'd like to be able to read it.

There's no such thing as <alloc.h>.
Yes there is. It might not be ISO standard, but there sure as hell are
alloc.h implementations out there.

To the OP :

Check out your call to firstnode in the append fnuction. Why are you
passing "int" as opposed to a number?

Oct 16 '06 #4
raghu wrote:
I have written code for single linked list...I get an error as
Expression syntax in the line marked with ////////. Please correct me
where am I going wrong. I compiled this in TURBO Compiler
I fixed your crap layout. My comment are marked "***nik"

#include <stdio.h>
#include <alloc.h>

/***nik non-standard header replace with stdlib.h ***/

struct node
{
int data;
struct node *link;
};

void main()

/***nik int main(void) ***/

{
int num = 10;
struct node *p;
p = NULL;
append(&p,num);

/***nik no prototype in scope. Didn't your compiler tell you this?
I'd put main() at the end ***/

getch();
/***nik why? ***/

}
struct node *firstnode(int num)
{
struct node *p;
p=(struct node*)malloc(sizeof(struct node));
/***nik don't cast malloc() ***/
p->data = num;
p->link = NULL;
return p;
}
append(struct node **q,int num)
/***nik no return type ***/

{
struct node *temp,*r;

if(*q == NULL)
*q = firstnode(int); ////////////////////////////
/*** *q = firstnode(num); maybe? ***/

else
{
temp = *q;
while (temp->link != NULL)
temp = temp->link;

r = malloc(sizeof(struct node));
r->data =n um;
r->link = NULL;
temp->link = r;
}
}
--
Nick Keighley

Oct 16 '06 #5

"raghu" <ra*********@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>I have written code for single linked list...I get an error as
Expression syntax in the line marked with ////////. Please correct me
where am I going wrong. I compiled this in TURBO Compiler

#include<stdio.h>
#include<alloc.h>
struct node
{
int data;
struct node *link;
};
void main()
{
int num=10;
struct node *p;
p=NULL;
append(&p,num);
getch();
}
struct node *firstnode(int num)
{
struct node *p;
p=(struct node*)malloc(sizeof(struct node));
p->data=num;
p->link=NULL;
return p;
}
append(struct node **q,int num)
{
struct node *temp,*r;
if(*q==NULL)
*q= firstnode(int); ////////////////////////////
-----------------^

Do you mean
*q= firstnode(num);
else
{
temp=*q;
while(temp->link!=NULL)
temp=temp->link;
r=malloc(sizeof(struct node));
r->data=num;
r->link=NULL;
temp->link=r;
}
return 0;
}
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project
Oct 16 '06 #6
raghu wrote:
I have written code for single linked list...I get an error as
Expression syntax in the line marked with ////////. Please correct me
where am I going wrong. I compiled this in TURBO Compiler
Next time, please use indentation.
#include<stdio.h>
#include<alloc.h>
Use <stdlib.hinstead of <alloc.h>.
struct node
{
int data;
struct node *link;
};
void main()
In standard C, main() must return integer and it's better to explicitly
indicate lack of parameters with the void keyword. Hence the better
form of the above would be:

int main(void)
{
int num=10;
Using a symbolic constant instead of a literal is more robust.
struct node *p;
p=NULL;
append(&p,num);
Since append() is called before it's defined, you should provide a
prototype for it. Place it after the #include statements.
getch();
This is a non-standard function and appears to be pointlessly called
here. Remove it.
}
struct node *firstnode(int num)
{
struct node *p;
p=(struct node*)malloc(sizeof(struct node));
In C, you need not cast the return value of malloc(). Doing so may
circumvent compiler diagnostics which may otherwise be useful. Also,
where possible, use the sizeof() operator on the relevant object rather
than it's type. If, later on, you modify the type of the object, you
need not touch the malloc() statement. It's automatically updated to
the correct type.

So a better form of the above statement is:

p = malloc(sizeof *p);

Also check the malloc() call for failure before proceeding.
p->data=num;
p->link=NULL;
return p;
}
append(struct node **q,int num)
Use int before append() to indicate the return value.
{
struct node *temp,*r;
if(*q==NULL)
*q= firstnode(int); ////////////////////////////
I think you meant to write:

*q = firstnode(num);
else
{
temp=*q;
while(temp->link!=NULL)
temp=temp->link;
r=malloc(sizeof(struct node));
r->data=num;
r->link=NULL;
temp->link=r;
}
return 0;
}
Oct 16 '06 #7

Thanks a lot guys. I shall follow your way of programming.. Thanks once
again for spending your valuable time in answering my problem.

Oct 16 '06 #8
raghu <ra*********@gmail.comwrote:
I have written code for single linked list...I get an error as
Expression syntax in the line marked with ////////. Please correct me
where am I going wrong. I compiled this in TURBO Compiler
I took the liberty of reformatting your code below. You have a number
of major problems, the syntax error you are seeing being only the most
obvious. int is a type, not a number, and it suggests that it's time
to take another look at your friendly C reference. (I leave
discussion of your other issues to other posters.)

(OP's code, reformatted with spaces, follows.)

#include<stdio.h>
#include<alloc.h>

struct node
{
int data;
struct node *link;
};

void main()
{
int num=10;
struct node *p;
p=NULL;
append(&p,num);
getch();
}

struct node *firstnode(int num)
{
struct node *p;
p=(struct node*)malloc(sizeof(struct node));
p->data=num;
p->link=NULL;
return p;
}

append(struct node **q,int num)
{
struct node *temp,*r;
if(*q==NULL)
*q= firstnode(int); ////////////////////////////
else
{
temp=*q;
while(temp->link!=NULL)
temp=temp->link;
r=malloc(sizeof(struct node));
r->data=num;
r->link=NULL;
temp->link=r;
}
return 0;
}
}

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Oct 16 '06 #9
"santosh" <sa*********@gmail.comwrites:
raghu wrote:
>void main()

In standard C, main() must return integer and it's better to explicitly
indicate lack of parameters with the void keyword. Hence the better
form of the above would be:

int main(void)
Correction: main() must return int.

int is a specific type; the word "integer" refers to the entire set of
integer types (char, short, int, long, etc.). It's a very important
distinction.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Oct 16 '06 #10
On Mon, 2006-10-16 at 18:26 +0000, Christopher Benson-Manica wrote:
raghu <ra*********@gmail.comwrote:
I have written code for single linked list...I get an error as
Expression syntax in the line marked with ////////. Please correct me
where am I going wrong. I compiled this in TURBO Compiler

I took the liberty of reformatting your code below. You have a number
of major problems, the syntax error you are seeing being only the most
obvious. int is a type, not a number, and it suggests that it's time
to take another look at your friendly C reference. (I leave
discussion of your other issues to other posters.)

(OP's code, reformatted with spaces, follows.)

#include<stdio.h>
#include<alloc.h>
<alloc.his nonstandard. Perhaps you want <stdlib.h>?
struct node
{
int data;
struct node *link;
};

void main()
main() returns int. main() returns int. main() returns int.

int main(void)
{
int num=10;
struct node *p;
p=NULL;
Combine this into
struct node *p = NULL;
append(&p,num);
No prototype. How can I know what this returns and accepts as
parameters?
getch();
Get rid of this. It just pisses people off.
}

struct node *firstnode(int num)
{
struct node *p;
p=(struct node*)malloc(sizeof(struct node));
p = malloc(sizeof *p);

Don't cast the return of malloc(). It hides the fact that you didn't
#include <stdlib.h>, it clutters the code, and it it poor style.

Don't use sizeof(type). It's almost never necessary, and it hinders
maintenance.
p->data=num;
p->link=NULL;
return p;
}

append(struct node **q,int num)
Don't depend on implicit int. It's bad style, and illegal in C99.
{
struct node *temp,*r;
if(*q==NULL)
*q= firstnode(int); ////////////////////////////
1) Error: "int" is a keyword, not a value.
2) Error: "/" found where it doesn't belong. Several times.
else
{
temp=*q;
while(temp->link!=NULL)
temp=temp->link;
r=malloc(sizeof(struct node));
r->data=num;
r->link=NULL;
temp->link=r;
This is almost guaranteed to be a logic error. The loop will never end.
What were you trying to do?
}
return 0;
}
}
--
Andrew Poelstra <http://www.wpsoftware.net/projects/>

Oct 17 '06 #11

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

Similar topics

35
by: wired | last post by:
Hi, I've just taught myself C++, so I haven't learnt much about style or the like from any single source, and I'm quite styleless as a result. But at the same time, I really want nice code and I...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
1
by: Pax S | last post by:
I need a button that will check (make true) two check boxes (fields) For the record that has the focus (the record on the form that I am presently looking at). The two check boxes would be like a...
4
by: Gary | last post by:
Hello, I'm hoping someone can shed some light on why my report does not output the same results as shown in preview mode, which is to move the position of a check box based on a field value (see...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
66
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
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 =...
2
by: Unpopular | last post by:
void directory::modification()//??????????? { clrscr(); cout<< "\n\t @@@@@@ @@@@@ @@@@@ @@@@@@ @@@@@ @ @ @@@@@@ "; cout<< "\n\t=====@ @ @ @ @ @ @@...
6
by: shapper | last post by:
Hello, I am creating a form that includes a few JQuery scripts and TinyMCE Editor: http://www.27lamps.com/Beta/Form/Form.html I am having a few problems with my CSS: 1. Restyling the Select
2
by: LilMeechc20 | last post by:
Hello, I have a group assignment that I have to do. We have to write a Tic Tac Toe game. One person in my group has managed to write the code for a multiplayer (human -vs- human) game and I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.