954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

extract token(word) from string

i need help.
i need to write a code that can extract word from string.
i had use cin.getline(string,size) to get th string and strtok(string," ") to extarct token. now i want to know how can i insert the token in array because i want to use the token for other purpose.

this what i had write

const size=100;
char string[size];
char *tokenPtr;
cout<<"string\n";
cin.getline(string,size);
tokenPtr =strtok(string," "); //bring string1 by separated by characters in string2

while (tokenPtr != NULL)
{
cout<

amen
Newbie Poster
17 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

i had a error---> cannot convert char * to char when i write this code as below

while (tokenPtr != NULL)
{
cout<

amen
Newbie Poster
17 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

i had change to code to this
while (tokenPtr != NULL)
{

temp[i]=* tokenPtr;
i++;
tokenPtr=strtok(NULL," ");
}

for (int j=0;j

amen
Newbie Poster
17 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

i think i had got it.it works

here is the code

#include
#include

int main()
{
//declaraction variable
//----------------------------
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>b;
if (b==0)
{return 0;}
}

i try to input string like--> here i go
then output show as below

temp[0]=here
temp[1]=i
temp[3]=go

let me know if there a simple or other way to get the program run..

thank you

amen
Newbie Poster
17 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

now..just need to think how to compare the token(word) with word in the file.txt that contain many word.
wish me luck

amen
Newbie Poster
17 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

here the code

#include <iostream.h>
#include <string.h>

int main()
{
	//declaraction variable
  	//----------------------------
   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++)
    	{
      	cout<<"temp["<<j<<"]="<<temp[j]<<"\n"; //write the token
      }
   cout<<"\n\n0 for exit\n";
	int b;
   cin>>b;
   if (b==0)
   {return 0;}
}

same as below,but now the code in the tags..
thank you

amen
Newbie Poster
17 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

Write a Java Applications to extract a portion of a character string and print the extracted string.

acsountharraj
Newbie Poster
2 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

1. Write a Java Applications to extract a portion of a character string and print the extracted string.
2. Write a Java Program to implement the concept of multiple inheritance using Interfaces.
3. Write a Java Program to create an Exception called payout-of-bounds and throw the exception.
4. Write a Java Program to implement the concept of multithreading with the use of any three
multiplication tables and assign three different priorities to them.
5. Write a Java Program to draw several shapes in the created windows.
6. Write a Java Program to create a frame with four text fields as name, street, city and pin code
with suitable tables. Also add a button called “my details”, When the button is clicked its
corresponding values are to be appeared in the text fields.
7. Write a Java Program to demonstrate the Multiple Selection List-box.
8. Write a Java Program to create a frame with three text fields for name, age and qualification and
a text field for multiple lines for address.
9. Write a Java Program to create Menu Bars and pull down menus.
10. Write a Java Program to create frames which respond to the mouse clicks. For each events with
mouse such as mouse up, mouse down, etc., the corresponding message to be displayed.
11. Write a Java Program to draw circle, square, ellipse and rectangle at the mouse click positions.
12. Write a Java Program which open an existing file and append text to that file.

acsountharraj
Newbie Poster
2 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You