Click here to Skip to main content
16,015,351 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Very Basic Question. Pin
Jon Hulatt4-Apr-02 21:34
Jon Hulatt4-Apr-02 21:34 
GeneralSplit strigs to substrings Pin
Nektarios Sourligas4-Apr-02 20:00
Nektarios Sourligas4-Apr-02 20:00 
GeneralRe: Split strigs to substrings Pin
Mazdak4-Apr-02 20:08
Mazdak4-Apr-02 20:08 
GeneralRe: Split strigs to substrings Pin
Nektarios Sourligas4-Apr-02 20:24
Nektarios Sourligas4-Apr-02 20:24 
GeneralRe: Split strigs to substrings Pin
Mazdak4-Apr-02 20:45
Mazdak4-Apr-02 20:45 
GeneralRe: Split strigs to substrings Pin
Mazdak4-Apr-02 20:47
Mazdak4-Apr-02 20:47 
GeneralRe: Split strigs to substrings Pin
Joaquín M López Muñoz4-Apr-02 20:24
Joaquín M López Muñoz4-Apr-02 20:24 
GeneralRe: Split strigs to substrings Pin
Paul M Watt4-Apr-02 20:34
mentorPaul M Watt4-Apr-02 20:34 
If you are using a standard char array, you can use a function called strtok. This function will allow you to step through a string and find all of the tokens, or substrings. Here is a short example:

#include "stdafx.h"
#include "stdlib.h"

#include <iostream>
using namespace std;

// This program will parse the string, and place each of the tokens, or substrings
// into the array vars.  When the string has been tokenized, the vars will be printed
// to the screen.

int main(int argc, char* argv[])
{
	char str[] = "Let us get out of here, NOW!";
	char *vars[10];

	int index = 0;
	//C: Specify the string to parse on the first call to strtok.
	//   The second parameter denotes the delimiter token to search for.
	//   We will search for a space " " and a comma ","
	vars[index] = strtok(str, " ,");
	//C: strtok returns NULL of there are no other tokens.
	while (vars[index] && 
		   index < 10 /*There is only space for ten strings.*/)
	{
		index++;
		//C: On each call after the first to strtok, you can pass in a NULL
		//   to the first parameter and it will keep searching the original
		//   string that you passed it.
		vars[index] = strtok(NULL, " ,");
	}

	//C: Print all of the tokens to the screen.
	int token;
	for (token = 0; token < index; token++)
	{
		cout << vars[token] << endl;
	}
	
	return 0;
}

GeneralRe: Split strigs to substrings Pin
Nektarios Sourligas4-Apr-02 22:45
Nektarios Sourligas4-Apr-02 22:45 
GeneralRe: Split strigs to substrings Pin
Paul M Watt4-Apr-02 23:24
mentorPaul M Watt4-Apr-02 23:24 
GeneralRe: Split strigs to substrings Pin
Michael Dunn5-Apr-02 16:42
sitebuilderMichael Dunn5-Apr-02 16:42 
GeneralCOM Pin
4-Apr-02 17:51
suss4-Apr-02 17:51 
GeneralRe: COM Pin
Paul M Watt4-Apr-02 17:56
mentorPaul M Watt4-Apr-02 17:56 
GeneralRe: COM Pin
Prem Kumar4-Apr-02 21:32
Prem Kumar4-Apr-02 21:32 
GeneralRedefining ATLASSERT Pin
nw603124-Apr-02 15:47
nw603124-Apr-02 15:47 
GeneralRe: Redefining ATLASSERT Pin
Christian Graus4-Apr-02 16:14
protectorChristian Graus4-Apr-02 16:14 
GeneralRe: Redefining ATLASSERT Pin
Gerald Schwab4-Apr-02 16:23
Gerald Schwab4-Apr-02 16:23 
GeneralRe: Redefining ATLASSERT Pin
nw603124-Apr-02 17:39
nw603124-Apr-02 17:39 
GeneralRe: Redefining ATLASSERT Pin
Gerald Schwab4-Apr-02 19:04
Gerald Schwab4-Apr-02 19:04 
GeneralRe: Redefining ATLASSERT Pin
Le centriste5-Apr-02 7:35
Le centriste5-Apr-02 7:35 
QuestionHow do I print a dialog box? Pin
atomicluis4-Apr-02 15:44
atomicluis4-Apr-02 15:44 
AnswerRe: How do I print a dialog box? Pin
Christian Graus4-Apr-02 16:03
protectorChristian Graus4-Apr-02 16:03 
GeneralRe: How do I print a dialog box? Pin
Jon Hulatt4-Apr-02 21:40
Jon Hulatt4-Apr-02 21:40 
GeneralRe: How do I print a dialog box? Pin
Christian Graus4-Apr-02 21:45
protectorChristian Graus4-Apr-02 21:45 
AnswerRe: How do I print a dialog box? Pin
Mazdak4-Apr-02 19:36
Mazdak4-Apr-02 19:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.