|
|
|
|
![]() ![]() |
Apr 25 2007, 12:52 AM
Post
#1
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 1 Joined: 25-April 07 Member No.: 21,628 |
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... 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... CODE _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 SeeYaa! ^^ |
|
|
|
May 3 2007, 01:30 AM
Post
#2
|
|
|
Member [ Level 2 ] Group: Members Posts: 71 Joined: 16-December 06 Member No.: 18,419 |
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.
|
|
|
|
Sep 25 2007, 08:41 PM
Post
#3
|
|
|
Advanced Member Group: Members Posts: 128 Joined: 12-February 05 From: St. Louis, MO Member No.: 2,612 |
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 ':' |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 7th October 2008 - 08:09 AM |