?
Solved

Parse comma delimeted string into an array

Posted on 2008-10-16
4
Medium Priority
?
758 Views
Last Modified: 2012-08-13
I am reading the name of an application from a registry value, however I need to change the code to read multiple application names from the registry value.  The registry value will be a comme delimeted string, and I think I need to read these values into an array and then launch these application.

As I have virtually no C experience, can someone please help me with this ?
success = get_registry_value(APPLICATION, "WorkstationRole", newApplication, sizeof newApplication);
	
if (success)
{	
	sprintf (WorkstationRole, "%s%s", path, newApplication);
 
	if(CreateProcess(NULL,
		WorkstationRole, // cmd line
		NULL, // process sa
		NULL, // thread sa
		FALSE, // inherit handles
		0, // flags
		NULL, // env
		NULL, // cur dir
		&sui,
		&pi))
{
// Close the thread handle as it is not required
CloseHandle(pi.hThread);

Open in new window

0
Comment
Question by:hairybarbarian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 100 total points
ID: 22729011
Assuming that newApplication is a char*, you can use strtok to split it up into tokens :

        http://www.cplusplus.com/reference/clibrary/cstring/strtok.html

char *newApplication;
 
char *token = strtok(newApplication, ",");
while (token) {
  /* use token here */
  token = strtok(NULL, ",");
}

Open in new window

0
 
LVL 45

Assisted Solution

by:sunnycoder
sunnycoder earned 100 total points
ID: 22729015

appname = strtok (newApplication, "," );
while (appname)
{
     //create process goes here ... appname has application name
     appname = strtok (NULL, "," );
}

Open in new window

0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22784387
May I ask what made you accept sunnycoder's response, and not mine ? It seems that we posted the same exact answer at the same time, so shared credit seems in order ... Or am I missing something ?
0
 

Author Closing Comment

by:hairybarbarian
ID: 31506640
Thank you.
Just what I needed, thanks again.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question