Jump to content



Welcome to AstaHost - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!

Toggle shoutbox Shoutbox Open the Shoutbox in a popup

@  yordan : (21 April 2014 - 09:11 PM) Hey, Ritesh, Did You Hear Me?
@  yordan : (14 April 2014 - 05:28 PM) By The Way, This Could Be An Interesting Subject For A Topic, What About Posting This Question? Let's See If Other People Have The Same Feeling Concerning Bootlists!
@  yordan : (13 April 2014 - 09:36 AM) Boot Order : Cd, [Usb,] Hard Drive :D
@  yordan : (11 April 2014 - 07:23 PM) I Simply Let The Bios Do That
@  Ritesh : (11 April 2014 - 10:23 AM) Is It Possible To Launch Fedora Live Cd Or Installation Disk From Hard Drive On Windows Platform Using Grub Mbr File.
@  Ritesh : (11 April 2014 - 10:21 AM) No U Are Not.. Btw.. I Have Question For You.
@  yordan : (10 April 2014 - 08:02 AM) You Are Partially Right.
I Was Not.
Nevertheless, I Am Again :)
@  Ritesh : (09 April 2014 - 07:33 PM) :P
@  Ritesh : (09 April 2014 - 07:33 PM) I Think U R Not..
@  yordan : (09 April 2014 - 09:28 AM) I'm The Master Of The Shoutbox!
@  yordan : (05 April 2014 - 10:32 PM) He-He
@  Ritesh : (04 April 2014 - 06:59 PM) Ha Ha Ha ....
@  yordan : (04 April 2014 - 11:15 AM) Welcome Back, Starscream!
@  yordan : (03 April 2014 - 02:31 PM) And I Hope That He Will Come Back Soon :)
@  yordan : (01 April 2014 - 02:53 PM) Nice, Ritesh Came, I'm Not Home Alone Today.
@  Ritesh : (01 April 2014 - 08:51 AM) Oh!!! Poor Dear Yordan..
@  yordan : (31 March 2014 - 10:02 AM) I'm A Poor Lonesome Cow-Boy
@  yordan : (27 March 2014 - 02:22 PM) He Is Unpatient Due To His Patients!
@  Ritesh : (27 March 2014 - 10:46 AM) :(
@  Ritesh : (27 March 2014 - 10:46 AM) He Is Busy With His Patients.

Photo
- - - - -

Help Spliting A String Into 3 Variables In C++ I have searched on the net but havent found much help


2 replies to this topic

#1 CaptainCPS-X

CaptainCPS-X

    Newbie [ Level 1 ]

  • Members
  • 1 posts

Posted 25 April 2007 - 12:52 AM

Hi there im new around here ^^, my original language is spanish so sorry for any wrong word i use,...

Im working on some features for my program to load a Favorite games list from a text file but the problem I have is not parsing the file, is processing a string and spliting it into 3 variables, then I will use them to insert as items in a List View control, I just dont know what is wrong in the following code...

//------------------------------------------------------------	

		TCHAR* pszRomname = NULL;
		TCHAR* pszTitle= NULL;
		TCHAR* pszHardware = NULL;
		char romname[256] = "";
		char title[256] = "";
		char hardware[256] = "";
		int i = 0;

		char str[] = "mslug:Metal Slug Super Vehicle-001:Neo-Geo,";
		
		char *pch;
		pch = strtok(str,":");

		while(pch != NULL)
		{
			if(i == 0) { sprintf(romname,"%s",pch); }
			if(i == 1) { sprintf(title,"%s",pch); }
			if(i == 2) { sprintf(hardware,"%s",pch); }

			pch = strtok(NULL,":");
			i++;
		}

		_stprintf(pszRomname, L"%s", romname);
		_stprintf(pszTitle, L"%s", title);
		_stprintf(pszHardware, L"%s", hardware);

		//------------------------------------------------------------

The app crashes with this code, maybe is because im converting the strings in a wrong way or something, I need them at the end like TCHARs and not 'char' that's why i use the _stprintf()...

oh, btw if I remove this it will not crash but of course I need those strings to add the items in the List View control...

_stprintf(pszRomname, L"%s", romname);
		_stprintf(pszTitle, L"%s", title);
		_stprintf(pszHardware, L"%s", hardware);

ThanX in advance for any help, it will be really appreciated :ph34r:

SeeYaa!
^^

#2 bluefish

bluefish

    Member [ Level 2 ]

  • Members
  • 71 posts

Posted 03 May 2007 - 01:30 AM

I'm no expert when it comes to Windows stuff in C++ - however, I can tell you that your problem must be in converting the char* to TCHAR*. I checked the values of the variables, and they're fine. I couldn't find the _sprintf function when I looked around, so I can't help you there, but try checking the documentation for what you're using to make sure you're using that function correctly.

#3 polarysekt

polarysekt

    Advanced Member

  • Members
  • 128 posts
  • Location:St. Louis, MO
  • Interests:computers, music

Posted 25 September 2007 - 08:41 PM

i didn't see where you initialised your TCHAR variables... you've declared them as pointers (pointing at NULL) -- so you're probably just trying to send data into the VOID...


try initialising them with:


pszRomname = new char[256];
pszTitle = new char[256];
pszHardware = new char[256];

_stprintf(pszRomname, L"%s", romname);
_stprintf(pszTitle, L"%s", title);
_stprintf(pszHardware, L"%s", hardware);

// insert them into your list ...

// but don't forget to call
// delete [] pszRomname;
// delete [] pszTitle;
// delete [] pszHardware;


also, your recursion is a little big...
don't forget you can increment pointer variables and and check the current pointer against ':'



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users