| | |
help me on linked list
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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 arrays bash binarysearch centimeter char convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o ide inches infiniteloop initialization interest kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix meter microsoft motherboard multi mysql odf open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer pointers posix power probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string strings suggestions systemcall test testautomation unix urboc user voidmain() wab win32api windows.h






