| | |
string: get token from string and compare token from text file
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2006
Posts: 17
Reputation:
Solved Threads: 0
i need to write a code on how can break a sentence into word and find out the word belong to.
example :
when user input a sentence cindy walk slow.
1.break the sentence into cindy,walk,slow.
2.get each word belong to and display.
- cindy is a noun
- walk is a verb
- slow is a adjective.
i had make 2 file text:
1. verb .txt
2. adjective
verb.txt
adjective
this is the code i had done:
the output:
input string
ali walk slow
walk is a verb
slow is a adjective
what i want to know is how i can get word ali belong to?
i didn't want to make a text file that contain of the noun.
if the word not in the verb.txt and adjective.txt,therefore it is a noun..
please help me..
anyway thank you.
example :
when user input a sentence cindy walk slow.
1.break the sentence into cindy,walk,slow.
2.get each word belong to and display.
- cindy is a noun
- walk is a verb
- slow is a adjective.
i had make 2 file text:
1. verb .txt
2. adjective
verb.txt
C++ Syntax (Toggle Plain Text)
eat walk ran sleep
adjective
C++ Syntax (Toggle Plain Text)
fast slow pretty
this is the code i had done:
C++ Syntax (Toggle Plain Text)
const size=100; //size of string char string[size],temp[size][32]; char *tokenPtr; int i=0; cout<<"input string\n"; cin.getline(string,size);//read line of string /*function char *strtok(char *s1,const char *s2) breaks s1 into token(word) separated by character in s2 */ tokenPtr =strtok(string," ");//pointer to first token while (tokenPtr != NULL) { strcpy(temp[i],tokenPtr);//save the token to array i++; tokenPtr=strtok(NULL," "); } for(int j=0;j<i;j++) { char word1[30],word2[30]; ifstream dictionary1("verb.txt"); ifstream dictionary2("adjective.txt"); while (dictionary1>>word1) if (strcmp(word1,temp[j])==0) cout<<temp[j]<<" is a verb \n"; while (dictionary2>>word2) if (strcmp(word2,temp[j])==0) cout<<temp[j]<<" is a adjective \n"; } return 0; }
the output:
input string
ali walk slow
walk is a verb
slow is a adjective
what i want to know is how i can get word ali belong to?
i didn't want to make a text file that contain of the noun.
if the word not in the verb.txt and adjective.txt,therefore it is a noun..
please help me..
anyway thank you.
set a boolean flag to indicate if the word is found in one of the two files. If not set then it must be a noun. Something like this sudo-code. Note: search second file ONLY if the word is not in the first file.
C++ Syntax (Toggle Plain Text)
set flag to false search verb.txt file for word if word found in verb.txt then set flag to true if flag still false begin search adjective.txt file for word if word found in adjective.txt file set flag to true end if if flag still false word is a noun
![]() |
Similar Threads
- Java's String Tokenizer (Java)
- extract token(word) from string (C++)
- C++ help (string class) (C++)
- String splitter (C)
- my #include <string> wont make "string" bold (C++)
Other Threads in the C++ Forum
- Previous Thread: Is this notation possible?
- Next Thread: Problem with object declaration
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






