If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > Urgent Help - C Language

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-09-08, 09:41
lawrencelowsy lawrencelowsy is offline
Registered User
 
Join Date: Jan 2008
Posts: 3
Question Urgent Help - C Language

I wrote a C language yesterda and found that there are some errors. However, I do not know how to fix them up.

Would appreciated if someone can help me.....THANKS!!!



--------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>

#define STR_MAX 254

#define NOUN 1
#define ADJECTIVE 2
#define VERB 3

typedef struct wordnode * wordnodePtr

typedef struct wordnode
{
char word[STR_MAX+1];
char meaning[STR_MAX+1];
wordnodePtr * next;
int dataType;
} WordNode;

typedef struct dictionary
{
wordnodePtr * head;
int wordCount;
int displayOption;
} Dictionary;

int main(void)
{
char string[STR_MAX+1];
int choice, exit;

Dictionary dict;
Init(dict);

exit = 0;
do{
printf("Search: ");
fgets(string, STR_MAX, stdin);

if( strcmp(string, "?") == 0)
{
printf("1. Add word\n"
"2. Delete word\n"
"3. Set display option\n"
"4. Exit display mode\n");
fgets(string, STR_MAX, stdin);
choice = atoi(string);

switch(choice)
{
case 1:
AddNewWord(dict);
break;
case 2:
DeleteWord(dict);
break;
case 3:
SetDisplayOption;
break;
case 4:
exit = 1;
break;
default:
break;
}
}else{
searchDictionary(dict, string);
}
} while( exit != 1);
}

Init(Dictionary * dict){
//Initialise dict linklist
dict->head = NULL
dict->wordCount = 0;
}

void AddToDictionary(Dictionary * dict, char * word, char * meaning, int dataType)
{
WordNode *newNode;
//add to linklist
newNode = ((WordNode *)malloc(sizeof(WordNode)));
if( newNode == NULL )
{
printf("Failed to allocate new memory space.");
}else{
strcpy(newNode->word, word);
strcpy(newNode->meaning, meaning);
newNode = dataType;
}
}

void SearchDictionary(Dictionary * dict, char * word)
{
int i, choice;
char string[STR_MAX+1];
char ** possibleList;
WordNode * current;
//search
i=0;
current = dict->head;
while( current != NULL )
{
if( strstr(word, current->word) == 0 )
{
if( dict->displayOption = current->dataType )
{
//print the possible list
printf("%d. %s\n", word, i++);
strcpy(possibleList[i], word);
}
}
current = current->next;
}
//select from the list
printf("\nEnter your choice: ");
fgets(string, STR_MAX, stdin);
choice = atoi(string);

if(possibleList[choice] == NULL)
{
printf("No such index");
return;
}

//display
current = dict->head;
while( current != NULL )
{
if( strcmp(possibleList[choice], current->word) == 0 )
{
printf("%s\n -----------------\n %s", word, meaning);
//done
return;
}
current = current->next;
}
}

int LoadDictionary(Dictionary * dict)
{
FILE * fp;
char * p;
char word[STR_MAX+1];
char meaning[STR_MAX+1];
char temp_str[STR_MAX+1];
char * filename = "dictionary.txt";

fp = fopen(filename, "r");
if( fp == NULL )
{
printf("Error");
return EXIT_FAILURE;
}

while(!feof(fp) && fgets(temp_str, STR_MAX, fp))
{
char word[STR_MAX+1], meaning[STR_MAX+1];
int dataType;
p = strtok(temp_str, ":");
strcpy(word, p);
p = strtok(NULL, ":");
dataType = p;
p = strtok(NULL, ":");
strcpy(meaning, p);
addToDictionary(dict, word, meaning, dataType);
}
}

void SaveToFile(Dictionary * dict)
{
char * filename = "dictionary.txt";
}

void AddNewWord(Dictionary * dict)
{
//User input

//scanf word, meaning, word type


//Call AddToDictionary(dict, word, meaning)

}
void DeletewWord(Dictionary * dict)
{
WordNode * current;
printf("Enter word to delete: ");
fgets(string, STR_MAX, stdin);

current = dict->head;
while( current != NULL )
{
if( strcmp(possibleList[choice], current->word) == 0 )
{
//found
printf("%s has been deleted\n", word;
free(current);
return;
}
current = current->next;
}

}

void SetDisplayOption(Dictionary * dict)
{
printf("Set Display Option:\n"
"1. Show All\n"
"2. Show Noun\n"
"3. Show Adjective\n"
"4. Show Verb");

fgets(string, STR_MAX, stdin);
dict->displayOption = atoi(string);
}
Reply With Quote
  #2 (permalink)  
Old 09-09-08, 09:45
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Where are the errors?
What are the errors?
What on earth is the question?!
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 09-09-08, 09:49
Erez Erez is offline
Registered User
 
Join Date: Sep 2008
Posts: 2
This doesn't even compile. You have several lines without closing semicolon ( ; ), calls to functions without correct parameters, casting errors. I suggest going over the compilation errors and fixing them, before returning. Also, an explanation of what you want to achieve with this code and what doesn't work will do. HTH
Reply With Quote
  #4 (permalink)  
Old 09-09-08, 10:06
lawrencelowsy lawrencelowsy is offline
Registered User
 
Join Date: Jan 2008
Posts: 3
Sorry....error as below:-

1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\testing.cpp(17) : error C2143: syntax error : missing ';' before '<class-head>'
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\testing.cpp(136) : error C2440: '=' : cannot convert from 'int' to 'WordNode *'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\testing.cpp(148) : error C2440: '=' : cannot convert from 'wordnodePtr *' to 'WordNode *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\testing.cpp(160) : error C2440: '=' : cannot convert from 'wordnodePtr *' to 'WordNode *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\testing.cpp(174) : error C2440: '=' : cannot convert from 'wordnodePtr *' to 'WordNode *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\testing.cpp(179) : error C2065: 'meaning' : undeclared identifier
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\testing.cpp(183) : error C2440: '=' : cannot convert from 'wordnodePtr *' to 'WordNode *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\testing.cpp(210) : error C2440: '=' : cannot convert from 'char *' to 'int'
1> There is no context in which this conversion is possible
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\testing.cpp(213) : error C3861: 'addToDictionary': identifier not found
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\testing.cpp(236) : error C2065: 'string' : undeclared identifier
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\testing.cpp(238) : error C2440: '=' : cannot convert from 'wordnodePtr *' to 'WordNode *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\testing.cpp(241) : error C2065: 'possibleList' : undeclared identifier
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\testing.cpp(241) : error C2065: 'choice' : undeclared identifier
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\testing.cpp(244) : error C2065: 'word' : undeclared identifier
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\testing.cpp(244) : error C2143: syntax error : missing ')' before ';'
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\testing.cpp(248) : error C2440: '=' : cannot convert from 'wordnodePtr *' to 'WordNode *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\testing.cpp(261) : error C2065: 'string' : undeclared identifier
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\testing.cpp(262) : error C2065: 'string' : undeclared identifier
1>asdadasdadad.cpp
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(15) : error C2143: syntax error : missing ';' before '<class-head>'
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(35) : error C3861: 'Init': identifier not found
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(54) : error C3861: 'AddNewWord': identifier not found
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(57) : error C3861: 'DeleteWord': identifier not found
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(60) : error C2065: 'SetDisplayOption' : undeclared identifier
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(69) : error C3861: 'searchDictionary': identifier not found
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(74) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(77) : error C2146: syntax error : missing ';' before identifier 'dict'
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(78) : warning C4508: 'Init' : function should return a value; 'void' return type assumed
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(91) : error C2440: '=' : cannot convert from 'int' to 'WordNode *'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(103 ) : error C2440: '=' : cannot convert from 'wordnodePtr *' to 'WordNode *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(115 ) : error C2440: '=' : cannot convert from 'wordnodePtr *' to 'WordNode *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(129 ) : error C2440: '=' : cannot convert from 'wordnodePtr *' to 'WordNode *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(134 ) : error C2065: 'meaning' : undeclared identifier
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(138 ) : error C2440: '=' : cannot convert from 'wordnodePtr *' to 'WordNode *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(165 ) : error C2440: '=' : cannot convert from 'char *' to 'int'
1> There is no context in which this conversion is possible
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(168 ) : error C3861: 'addToDictionary': identifier not found
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(191 ) : error C2065: 'string' : undeclared identifier
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(193 ) : error C2440: '=' : cannot convert from 'wordnodePtr *' to 'WordNode *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(196 ) : error C2065: 'possibleList' : undeclared identifier
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(196 ) : error C2065: 'choice' : undeclared identifier
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(199 ) : error C2065: 'word' : undeclared identifier
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(199 ) : error C2143: syntax error : missing ')' before ';'
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(203 ) : error C2440: '=' : cannot convert from 'wordnodePtr *' to 'WordNode *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(216 ) : error C2065: 'string' : undeclared identifier
1>c:\documents and settings\lim mingshi\my documents\visual studio 2008\projects\testing\testing\asdadasdadad.cpp(217 ) : error C2065: 'string' : undeclared identifier
1>Generating Code...
1>Build log was saved at "file://c:\Documents and Settings\Lim Mingshi\My Documents\Visual Studio 2008\Projects\testing\testing\Debug\BuildLog.htm"
1>testing - 43 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On