| | |
help me 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:
i am having this compiler error:
Warning] passing arg 2 of `strcmp' makes pointer from integer without a cast
for this line of code:
the code is:
C Syntax (Toggle Plain Text)
void AddWords( char text[30]) { check=head; while (check!=NULL) { if (strcmp(check->words,text[30])==0) { check->numWords++; break; } else { newNode=getmem(); strncpy(newNode->words,text, 29); newNode->next=head; head=newNode; } check=check->next; }
i am having this compiler error:
Warning] passing arg 2 of `strcmp' makes pointer from integer without a cast
for this line of code:
C Syntax (Toggle Plain Text)
if (strcmp(check->words,text[30])==0)
here is the whole program:
line in bold when debugged is giving the value of currunt->words as Could not watch this variable
line in bold when debugged is giving the value of currunt->words as Could not watch this variable
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
struct doc_words
{
char words[30];
int numWords;
struct doc_words *next;
};
struct doc_words *head=NULL;;
struct doc_words *current;
struct doc_words *check;
struct doc_words* newNode;
//char *calloc();
struct doc_words *getmem()
{
struct doc_words *p;
//p = malloc(sizeof(struct doc_words));
p = (struct doc_words*)malloc(sizeof(struct doc_words));
if(!p)
{printf("out of memory");
return(0);
}
else
return(p);
}
void AddWords( char text[30])
{
current=head;
char temp[30];
strncpy(temp,text,29);
do
{
if (current->words==temp)
{
current->numWords++;
break;
}
check=check->next;
}while (check!=NULL);
else
{
newNode=getmem();
strncpy(newNode->words,text, 29);
newNode->next=head;
head=newNode;
break;
}
}
void extract_words_from_file()
{
char word[30];
FILE *ifp;
if ((ifp=fopen("C:\\collins_tirivamwe\\DSA\\text.txt","r"))!=NULL)
{
while (fscanf(ifp,"%s",word)!=EOF)
{
printf("%s",word);
AddWords(word);
}
fclose(ifp);
}
else
printf("error");
}
void read()
{
printf("words in list");
struct doc_words *current= head;
while (current!=NULL)
{
printf("%s\n",current->words);
current=current->next;
}
}
int getCount()
{
int count=0;
struct doc_words *current= head;
while (current!=NULL)
{
count++;
current=current->next;
}
printf("\n %d",count);
return (count);
}
/*
int getCount(char word[30])
{
int count=0;
struct doc_words *p = head;
while (p!=NULL)
{
if (strcmp(p->word,word)==0)
{
count++;
p=p->next;
}
else
{
p=p->next;
}
}
return(count);
}
*/
int main()
{
int p=0;
extract_words_from_file();
p=getCount();
// printf("\nnumber of words are %d",p);
read();
system("PAUSE");
return 0;
} Last edited by ~s.o.s~; Oct 24th, 2006 at 2:24 pm.
•
•
•
•
here is the whole program:
line in bold when debugged is giving the value of currunt->words as Could not watch this variable
If you want to win, you must not loose (Alan Ford)
When I post something to this thread its not there. Whats happening here.
FOR tiriamwe: Ok fix the code becouse it wont compile. Read this. Posting errors of your prog
EDIT: Its ok now but there is some kind a bug when posting, becouse if I reply to 6th post of this thread my post is missing.
FOR tiriamwe: Ok fix the code becouse it wont compile. Read this. Posting errors of your prog
C Syntax (Toggle Plain Text)
test16.cpp: In function `void AddWords(char*)': test16.cpp:54: parse error before `else' test16.cpp:60: break statement not within loop or switch test16.cpp: At global scope: test16.cpp:62: parse error before `}' token
Last edited by andor; Oct 24th, 2006 at 11:15 am.
If you want to win, you must not loose (Alan Ford)
•
•
•
•
C Syntax (Toggle Plain Text)
do { if (current->words==temp) { current->numWords++; break; } check=check->next; }while (check!=NULL); else {
do a
if b
end a
else b
end b
gr Niek
![]() |
Similar Threads
- Removing an item from head of linked list (C)
- help implementing singly linked list (C++)
- How to read in a sentence and insert in to linked list? (C++)
- Linked List using pointers (C++ ADT) (C++)
- Why doesn't this remove the last node in a linked list? (C++)
- Cannot figure out how to implement linked list and rbtree for a project! (Java)
- Linked List (C++)
- help by sorting a simply linked list (C)
Other Threads in the C Forum
- Previous Thread: Keypress Detection
- Next Thread: can anyone give me another way of solvin this problem?
| Thread Tools | Search this Thread |
* adobe ansi api array asterisks binarysearch calculate centimeter char character cm convert copyanyfile copyimagefile copypdffile cprogramme createcopyoffile createprocess() csyntax directory feet fflush fgets file floatingpointvalidation fork frequency givemetehcodez global gtkgcurlcompiling gtkwinlinux hacking highest homework i/o inches infiniteloop input interest intmain() iso keyboard kilometer km linked linkedlist linux linuxsegmentationfault list locate lowest match meter microsoft mqqueue mysql number oddnumber odf open opendocumentformat openwebfoundation owf pattern pdf performance posix power probleminc program programming pyramidusingturboccodes read recv recvblocked repetition reversing scanf scheduling segmentationfault send single socketprograming socketprogramming stack standard string suggestions systemcall unix urboc user variable voidmain() wab whythiscodecausesegmentationfault win32api windows.h windowsapi






