| | |
extract token(word) from string
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2006
Posts: 17
Reputation:
Solved Threads: 0
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<<tokenPtr<<"\n";
tokenPtr=strtok(NULL," ");
}
i had come across function strcspn, and i want to know how it work.
please give me some idea?
thank your.
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<<tokenPtr<<"\n";
tokenPtr=strtok(NULL," ");
}
i had come across function strcspn, and i want to know how it work.
please give me some idea?
thank your.
•
•
Join Date: Feb 2006
Posts: 17
Reputation:
Solved Threads: 0
i think i had got it.it works
here is 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;}
}
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
here is 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;}
}
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
•
•
Join Date: Feb 2006
Posts: 17
Reputation:
Solved Threads: 0
here the code
same as below,but now the code in the tags..
thank you
C++ Syntax (Toggle Plain Text)
#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
•
•
Join Date: Jul 2009
Posts: 2
Reputation:
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.
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.
![]() |
Similar Threads
- Java's String Tokenizer (Java)
- Display Longest and Shortest Word in a String (C++)
- string: get token from string and compare token from text file (C++)
- Word Counting (C++)
Other Threads in the C++ Forum
- Previous Thread: Problem Passing Sturcture Object To Queue - Linux?
- Next Thread: Find median using pointers
Views: 10505 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





