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

need help on linked list

the function first search a word from the linked list. if found it then increment the numWords (number of words in listfor that word) and if not found it shoud create a new node for the word.

the code is:

Expand|Select|Wrap|Line Numbers
  1. void AddWords( char text[30])
  2. {
  3.  
  4.  check=head;
  5.  
  6. while (check!=NULL)
  7.       {
  8.        if (strcmp(check->words,text[30])==0)
  9.           {
  10.             check->numWords++;
  11.             break;
  12.           }
  13.        else
  14.            {                                
  15.              newNode=getmem();
  16.              strncpy(newNode->words,text, 29);
  17.              newNode->next=head;
  18.              head=newNode;                                
  19.            }
  20.       check=check->next;     
  21.  
  22. }

i am having this compiler error:

Warning] passing arg 2 of `strcmp' makes pointer from integer without a cast

for this line of code:

Expand|Select|Wrap|Line Numbers
  1. if (strcmp(check->words,text[30])==0)
Oct 24 '06 #1
8 1368
the function first search a word from the linked list. if found it then increment the numWords (number of words in listfor that word) and if not found it shoud create a new node for the word.

the code is:

Expand|Select|Wrap|Line Numbers
  1. void AddWords( char text[30])
  2. {
  3.  
  4.  check=head;
  5.  
  6. while (check!=NULL)
  7.       {
  8.        if (strcmp(check->words,text[30])==0)
  9.           {
  10.             check->numWords++;
  11.             break;
  12.           }
  13.        else
  14.            {                                
  15.              newNode=getmem();
  16.              strncpy(newNode->words,text, 29);
  17.              newNode->next=head;
  18.              head=newNode;                                
  19.            }
  20.       check=check->next;     
  21.  
  22. }

i am having this compiler error:

Warning] passing arg 2 of `strcmp' makes pointer from integer without a cast

for this line of code:

Expand|Select|Wrap|Line Numbers
  1. if (strcmp(check->words,text[30])==0)

Try this:
if (strcmp(check->words,text)==0)
Two arguments to strcmp shd. be adresses always..
Array name is equal to its address so pass text only..
Oct 24 '06 #2
arne
315 Expert 100+

Warning] passing arg 2 of `strcmp' makes pointer from integer without a cast

for this line of code:

Expand|Select|Wrap|Line Numbers
  1. if (strcmp(check->words,text[30])==0)
It's a warning, not an error. The compiler warns you that strcmp expected another type for its 2nd argument, namely 'const char *', but you passed an int. So the compiler will translate it, but it may not what you wanted ...

BTW, why did you start a new thread? Didn't we discuss this yesterday? What was wrong with thread http://www.thescripts.com/forum/thread552877.html ??
Oct 24 '06 #3
i tried that but when debugging i am having this error

An Access violation(segment fault) raised in your program.

the line of code crushinhg the program is:


Expand|Select|Wrap|Line Numbers
  1. if (strcmp(check->words,temp)==0)  
Oct 24 '06 #4
arne
315 Expert 100+
i tried that but when debugging i am having this error

An Access violation(segment fault) raised in your program.

the line of code crushinhg the program is:


Expand|Select|Wrap|Line Numbers
  1. if (strcmp(check->words,temp)==0)  
In my program? IIRC, I haven't sent you any program :)
Oct 24 '06 #5
arne
315 Expert 100+
In my program? IIRC, I haven't sent you any program :)
Oops, these were the compiler's word spoken to you, not your words spoken to me ... got it.
Oct 24 '06 #6
Oops, these were the compiler's word spoken to you, not your words spoken to me ... got it.
in just dont get it . what are u trying to say
Oct 24 '06 #7
Try this:
if (strcmp(check->words,text)==0)
Two arguments to strcmp shd. be adresses always..
Array name is equal to its address so pass text only..
i tried that but when debugging i am having this error

An Access violation(segment fault) raised in your program.

the line of code crushinhg the program is:



Expand|Select|Wrap|Line Numbers
  1. if (strcmp(check->words,temp)==0) 
Oct 24 '06 #8
arne
315 Expert 100+
i tried that but when debugging i am having this error

An Access violation(segment fault) raised in your program.

the line of code crushinhg the program is:



Expand|Select|Wrap|Line Numbers
  1. if (strcmp(check->words,temp)==0) 
It should be 'text', not 'temp', I think.
Oct 24 '06 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: C++fan | last post by:
Suppose that I define the following class: class example_class{ public: example_class(); void funtion_1(); void function_2(); protected:
5
by: Dream Catcher | last post by:
1. I don't know once the node is located, how to return that node. Should I return pointer to that node or should I return the struct of that node. 2. Also how to do the fn call in main for that...
10
by: Kent | last post by:
Hi! I want to store data (of enemys in a game) as a linked list, each node will look something like the following: struct node { double x,y; // x and y position coordinates struct enemy...
6
by: Steve Lambert | last post by:
Hi, I've knocked up a number of small routines to create and manipulate a linked list of any structure. If anyone could take a look at this code and give me their opinion and details of any...
4
by: dssuresh6 | last post by:
Whether browsing forward or backward can be done using a singly linked list. Is there any specific case where a doubly linked list is needed? For people who say that singly linked list allows...
13
by: XXXXXX.working.in.my.blood | last post by:
hi all, i need help with linked lists... the problem is this, "reverse the contents of a singly linked list without using a temporary node"... solution with code will be appreciated...
5
by: Y2J | last post by:
I am working through this book on C++ programming, the author is speaking of using linked lists. He gave and example which I found confusing to say the least. So I rewrote the example in a way that...
12
by: joshd | last post by:
Hello, Im sorry if this question has been asked before, but I did search before posting and couldnt find an answer to my problem. I have two classes each with corresponding linked lists, list1...
51
by: Joerg Schoen | last post by:
Hi folks! Everyone knows how to sort arrays (e. g. quicksort, heapsort etc.) For linked lists, mergesort is the typical choice. While I was looking for a optimized implementation of mergesort...
0
by: Atos | last post by:
SINGLE-LINKED LIST Let's start with the simplest kind of linked list : the single-linked list which only has one link per node. That node except from the data it contains, which might be...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.