473,387 Members | 1,529 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,387 software developers and data experts.

Quene display

Kay
This function is used to display the context of a queue. I input an
integer comparing with the queue cuisine number, if cuisine number is
same as the input, it shows the context. However, it cannot do what I
want. Did I do sth wrong ?

void DisplayRestaurantByCuisine( Queue * q, char input){

QueueNode * tmp;
char * item, * cuisine, *mode;

cout << "In restaurant by cuisine";
while(!QueueEmpty(q)){
tmp = q->front;
item = tmp->item;
cuisine = tmp->cuisine;
mode = tmp->mode;

if( input == cuisine ){ <-----------comparing
cout << item << mode << endl;
}
q->front = tmp->next;
}

Jul 22 '05 #1
2 1741
Kay wrote:

This function is used to display the context of a queue. I input an
integer comparing with the queue cuisine number, if cuisine number is
same as the input, it shows the context. However, it cannot do what I
want. Did I do sth wrong ?

void DisplayRestaurantByCuisine( Queue * q, char input){

QueueNode * tmp;
char * item, * cuisine, *mode;

cout << "In restaurant by cuisine";
while(!QueueEmpty(q)){
tmp = q->front;
item = tmp->item;
cuisine = tmp->cuisine;
mode = tmp->mode;

if( input == cuisine ){ <-----------comparing
cout << item << mode << endl;
}
q->front = tmp->next;
}


Aehm. This function modifies the queue by assigning something
to q->front. That is unusal for a display function. The
purpose of a display function is to display, nothing more.

The comparsion seems to be suspect (but I can't tell this
for sure, since you always just present code snippets without
context):

input denotes a single character
cuisine is a pointer to chararacter

So the above should not even compile due to data type
missmatch.
So if I assume that you retyped your code, instead of
cut&paste-ing the original code, and input in reality is

void DisplayRestaurantByCuisine( Queue * q, char* input){

(note: I changed 'char input' to 'char* input)

then

if( input == cuisine ){

does not do what you want: It compares 2 pointers and not
what the pointers point to. Comparing C-style strings is
done with a helper function strcmp

if( strcmp( input, cuisine ) == 0 ){

That leaves us with your looping construct. There is a funny
thing: A display function that loops as long as the data structure
is not empty.
Well. A display function has to display and leave the original
data structure as it is. But that also means: If the queue was
empty when the function starts, it stays empty. If the queue
was not empty, then just be outputting that queue it should
not become empty.
void DisplayRestaurantByCuisine( Queue * q, char* input)
{
QueueNode * tmp;
char * item, * cuisine, *mode;

cout << "In restaurant by cuisine";

tmp = q->front;

while( tmp != 0 ){
item = tmp->item;
cuisine = tmp->cuisine;
mode = tmp->mode;

if( strcmp( input, cuisine ) == 0 ){
cout << item << mode << endl;
}

tmp = tmp->next;
}
}
Don't get me wrong. But I think you are fighting too much right
now: You are fighting with very basic C knowledge and handling
dynamic data structures. This is most likely bound to fail with
a loud crash. Start simpler. Start with the C basics (or since
this is C++, start with C++ basics and throw C-style strings
out of the window). In doing so a good book as an absolute
must. See the FAQ for recommendations.
Only after you got fluent in basic C or C++, start with working
on dynamic data structures. Things like the above (comparing
pointers when you want to compare strings) *must* not happen when
you are tackling dynamic data structures. You can't study calculus
when you have problems with basic equation rearrangement.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #2

"Kay" <er*********@yahoo.com.hk> wrote in message
news:41**************@yahoo.com.hk...
This function is used to display the context of a queue. I input an
integer comparing with the queue cuisine number, if cuisine number is
same as the input, it shows the context. However, it cannot do what I
want. Did I do sth wrong ?

void DisplayRestaurantByCuisine( Queue * q, char input){

QueueNode * tmp;
char * item, * cuisine, *mode;

cout << "In restaurant by cuisine";
while(!QueueEmpty(q)){
tmp = q->front;
item = tmp->item;
cuisine = tmp->cuisine;
mode = tmp->mode;

if( input == cuisine ){ <-----------comparing
This attempts to compare a pointer with a character.
The language does not define such a thing.

If you want to compare the character 'input' with
the one pointed to by the pointer 'cuisine', then
dereference the pointer to get at the character
it points to.

if(input == *cuisine)

cout << item << mode << endl;
}
q->front = tmp->next;
}


-Mike
Jul 22 '05 #3

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

Similar topics

3
by: StepH | last post by:
Hi, I'm building a little application, which the goal is to: 1./ Collect data via Serial line and or via a file (for playback). 2./ Display these data as graph, oscilloscope, ... How manage...
1
by: FrankBooth | last post by:
Hello, I have a list of names, and when I click ona name I want the extar info to show and then I want to clcik and hide it again. I have the following HTML which works perfectly if I use one...
23
by: Mat | last post by:
<div id="container"> <div id="main"> <div id="header"> <p class="Address">123 Fake Street, </p> <p class="City">Crazy City, </p> <p class="Province">Ontario </p> <p class="PostalCode">H0H...
3
by: shreddie | last post by:
Could anyone assist with the following problem? I'm using JavaScript to hide/show table rows depending on the option selected in radio buttons. The script works fine in IE but in Firefox the...
1
by: Tristan Miller | last post by:
Greetings. I am trying to write a function which toggles the display of a certain class of <div> elements in an HTML page. The CSS file initially sets some classes to "display: none", and...
2
by: Tuvas | last post by:
I am trying to write a function that holds a variable-length quene. The quene has 2 bits of information. At some point, I would like to remove bits of this quene, when they are completed. Is there...
0
by: Ferry Boender | last post by:
Hi, I'm relatively new to Xlib programming, and I ran into a little problem. I'm trying to insert keypress events into a X window. The following code works: ...
1
by: RonY | last post by:
I have a dropdown which calls SetTimePeriod method on change the selection. In the JS function, I reset the field style.display based on what the selection is. This works fine with IE but not working...
15
by: cssExp | last post by:
hello, Rather than going on a wild explanation on what's the the problem, it'll be much quicker and easier if i let you look at it yourself, so I'll post my page source (actual contents taken out,...
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: 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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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,...

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.