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

free web hosting
Free Web Hosting > Computers & Tech > Programming > Programming General > C, C++ & Visual C++

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

CaptainCPS-X
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 smile.gif

SeeYaa!
^^

 

 

 


Reply

bluefish
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.

Reply

polarysekt
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


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : spliting, string, 3, variables, c, searched, net, havent, found

  1. String Theory
    (9)
  2. Looking For The Perfect Cms...
    Haven't found one yet. (6)
    Well as some of you may know, I've been playing around with Joomla for a while. I've also
    gotten really good at it! Now though, I'm finding Joomla isn't up to it in the way of
    features. You have to get a component or plugin for almost everything. Seeing as Joomla 1.5 (which
    is what I'm using) isn't all that old, there aren't enough extensions for it and like
    none for what I want. Also, most people make them under the Creative Commons license for 1.5, and I
    don't want stupid little ads all over my site. With the old version (1.0.13 I ....
  3. Strange Ascii Code 22 Character Detected In Connection String
    (9)
    Warning: Unexpected character in input: '' (ASCII=22) state=1 in
    /usr/local/cpanel/cgi-sys/php4 on line 928 Parse error: syntax error, unexpected T_STRING in
    /usr/local/cpanel/cgi-sys/php4 on line 928 i get that when i get on to my site:
    http://eggie.sphosting.com how to solve it?....
  4. A Lot Of Infomation About Cod4 Found On The Internet
    (0)
    here is information about cod 4 that i found on the internet QUOTE Call of Duty 4: Modern
    Warfare is a first-person shooter developed by Infinity Ward and published by Activision for
    Windows, Xbox 360, and PlayStation 3. It will be the eighth installment in the Call of Duty video
    game series (including expansions), the first not to be set during World War II, and the first to be
    rated "M" for Mature by the ESRB. It was announced on April 25, 2007 , and will be released
    worldwide on November 5, 2007. Contents * 1 Story o 1.1 Setting o 1.2 P....
  5. Check For Occurence Of Substring In String
    (3)
    Hi, I've been working on a personal messenger, and one of the main problems I'm having is
    that if there are 10 or so replies to a message, you end up with a subject like this: Re: Re: Re:
    Re: Re: Re: Re: ..... etc. you get the picture Is there a function on PHP to check for an occurence
    of a substring in a string? So I could check if the subject already has a "Re: " in it? It would be
    really helpful, thanks!....
  6. Php Long Variables
    How do you make them? (5)
    Don't ask why but I need to make a long variable that contains ' " ; and ) meaning I cannot
    use: CODE $var=('Test'); It will create an error. Here is an example of
    what I am talking about: CODE $var=("I want to use ' and " while allowing
    html and not using htmlspecialchars"); Basicly is what I want is a CODE
    echo<<<END This is some echo. I can use ' " ) and; without using
    htmlspecialchars END; Is there a way to make a simalur code that works with variables? Do you ....
  7. $_get Issue (urgent!)
    Get variables not working (11)
    I have this really urgent problem with $_GET variables. They aren't working properly, and
    my site's pretty much based around them. Take this example from my Personal Messenger system.
    index.php?p=messenger&action=compose This should take you to the compose message page of the
    messenger, but it doesn't. It recognises the '?p=messenger' bit, and takes you to the
    messenger page, but it completely ignores the '&action=compose' bit. For some reason, it
    occurs in some parts of the site, and not in others. Could you please fix this problem ASA....
  8. Folder Of Frontpage?
    Found A Folder (8)
    I got microsoft xp pro about 2 months ago and installed it then 3 days ago i noticed a folder called
    microsoft fronpage even though i never installed it. it contained one folder called version3.0 which
    contained a folder called bin which contained nothing. Can anybody explain this to me. N.B. I also
    looked at my mates computer and it had it also and he never installed frontpage /ohmy.gif"
    style="vertical-align:middle" emoid=":o" border="0" alt="ohmy.gif" />....
  9. Php Any Variable In String.
    (1)
    OK well I am making a new php program and I am trying to add bbcode to it. Anyway I was going to
    replace each thing by it self, but that could cause errors. Anyway is there a way to make a variable
    be anything? Here is an example: CODE This is the bbcode:
    [color=00FF00]Hey[/color] In my php: $bbcode =
    array("[color=".$a."]"); $html = array( "<font
    color='#".$a."'>"); $topic_content =
    str_replace($bbcode, $html, $posted_bbcode)....
  10. Sorting A String Vector
    (0)
    I did this code for a reason... It was a school project... I could not find this info anywhere...
    Maybe it will be use to some1 else. /smile.gif" style="vertical-align:middle" emoid=":)" border="0"
    alt="smile.gif" /> #include #include #include using namespace std; int main() { int
    count=0; vector Names(2); Names ="Alexa"; Names ="Alexc"; Names ="Alexb"; cout while(count
    { cout count++; } int i,j; int min; for(i=0;i { min = i; for (j = i + 1; j { if
    (Names Names .swap(Names ); } count=0; cout while(count { cout count....
  11. How To Remove Query String Using Regular Expressions
    (4)
    Hi, I'm a complete newbie using regular expressions and what i want to do is to remove all the
    parameters of the query string of any url using regular expressions, how can i do this? For example
    if i have some urls like these: http://www.domain.com/file1.php?var1=value1&var2=value2
    http://www.domain.com/file2.php?var1=value1&var2=value2
    http://www.domain.com/file3.php?var1=value1&var2=value2 I want to only get these ones:
    http://www.domain.com/file1.php http://www.domain.com/file2.php http://www.domain.com/file3.php
    If it is possible please post no....
  12. Major Flaw Found In .ani File Through All Major Ms Operating Systems
    (2)
    I have been keeping regulars updates on trap about this and I thought the members of astahost should
    know about this as well. http://www.trap17.com/forums/index.php?sho...mp;#entry316934 It is
    recommend that you read al lthe post I made about this topic since the new articles theses posts are
    comign from seem to be getting worse about this security risk. This flaw has been found from
    Windows 98 up to vista.....
  13. C# Tutorial : Lesson 2 - Variables & Operators
    (0)
    Variables A Variable is a named location that stores a value. Although variables are
    physically stored in the RAM, their actual memory address is not known to the programmer. We can use
    the variables via the name we give them. These are the rules for naming a variable:- The name must
    begin with a letter or an underscore & can be followed by a sequence of letters (A-Z), digits (0-9)
    or underscore (_) Special Characters such as ? - + * / \ ! @ # $ % ^ ( ) { } , ; :
    . cannot be used in the variable name. A variable name must not be the same a....
  14. Php String To Int Typecasting
    (5)
    I've been working on writing this program that needs strings to be converted to integers.
    Sometimes PHP works by doing the converting for me, but sometimes it just breaks down and quits
    working. I've got no idea why. $sub1 = 0+substr($text, 0, 3); $sub2 =
    0+substr($text, 3, 6); $sub3 = 0+substr($text, 6, 9); $sum =
    0+$sub1+$sub2+$sub3; echo $sum; Basically, $text is a string of numbers
    that looks something like: 296294255268313 and so on. Then I use substr to get the first three
    digits/letters of �....
  15. Pascal For Beginners - Part One
    The syntax, variables, input and output (7)
    This is the first part of my Pascal tutorial for beginners. Here is what the complete tutorial
    contains, and it might get expanded (some parts are not written yet): Part One Introduction
    What do you need to start? The program layout (organisation) and syntax Variables And what if
    there is an error? "Hello World" Input & Output Examples Swapping numbers Reading and writing
    multiple variables Part Two Conditions The IF condition The CASE condition Loops
    The FOR loop The WHILE loop The REPEAT loop Examples Checking whether a numb....
  16. Check Out This Interesting Information I Found.
    Science research. (0)
    QUOTE Bone, Knee, Hip and Joint Advances "Recommended. The information in this program, as well
    as the entire series, is up-to-date and of interest to both general audiences and to medical
    specialists." -EMR Online "Osteoporosis" - a new diagnostic device screens for signs of weakening of
    the bones; "See Through Bones" - a new x-ray machine which offers doctors extremely accurate details
    of bones; "Dem Bones" - lasers can now be used to stimulate bone growth; "Thinking Knee" - a new
    artificial knee is computerized, meaning amputees will find walking easier; "Artifici....
  17. Burn Iso To Hd?
    Found on the net it IS possible but none explaining HOW to do it :-( (20)
    Hi there, (Don't know if this is the right forum for this. And it also applies to all other
    OS's I guess. Though I'm in Ubuntu LiveCD at the moment!) Got a question, I've read
    on the net it IS possible to 'burn' an ISO file to a partition on the harddisk?! Though
    they don't say HOW to do it. I've been searching google like all day only for this and
    getting pretty desperate on this! /mellow.gif" style="vertical-align:middle" emoid=":mellow:"
    border="0" alt="mellow.gif" /> Anyone in here that knows how to do this? My idea ....
  18. Quickly Create Form Variables
    simple form, variable creation, referer check, safe guard variables (5)
    The reason I wanted to share this is I've seen so many people do this with their forms when
    using PHP. CODE $username = $_POST['username']; $password =
    sha1($_POST['password']); $another_var =
    $_POST['another_var']; ... and so on, just imagine if you had a large
    number of form inputs, do you really want to create each and every variable name? Why people do
    this, is probably due to most of the examples I've seen on the web, that does not show an easier
    and much quicker ....
  19. Note: How To Retrieve Variables From Function To Another
    (5)
    I have been having troubles with this but I found out a solution to this. The problem is to declare
    variables inside a function and retrieve its value from another function--but that doesn't work.
    Here is an example of the wrong thing to do: CODE function firstFunc () {      var
    aVariable = oneValue; } function getVariable () {      trace (aVariable); }
    The trace would return (undefined) because it is undefined in that exact function. Solution: do
    not declare variables inside a function. If you have to, use _root. variableNa....
  20. New Game - Urban Rivals
    I found it yesterday! (7)
    Hello everyone I found a new online game yesterday and I think its really good. Its similar to
    Magic The Gathering. You play with a deck of cards and try outwit your opponent. You can also
    'train' your cards to make them more powerfull and give them special powers. Its different
    to magic in one major way though! There's a random number used when calculating the winner.
    So although you might think your card will win, there is the chance it will still loose. As I said
    its a great game so if you enjoyed Magic then you should definatley try it out. http:/....
  21. Found Some Good Blogs With Tons Of Ebooks
    (2)
    http://www.mzworld.com Http://www.mzworld.com/ebooks List of Free E-books OS Programming
    Programs etc http://www.cec.uchile.cl/~lindsey/tutorial.htm O'Reilly online
    http://www.oreilly.com/openbook/ http://sysadmin.oreilly.com/ Computer books and manuals
    http://www.hoganbooks.com/freebook/webbooks.html http://www.informit.com/itlibrary/
    http://www.fore.com/support/manuals/home/home.htm
    http://www.adobe.com/products/acrobat/webbuy/freebooks.html The Network Book
    http://www.cs.columbia.edu/netbook/ Some #bookwarez.efnet.irc links http://www.e....
  22. User Authentication Session Handling Problems
    Authorization server variables not staying across pages (14)
    This is quite a bit of problem I am facing, and I cannot point exactly where I am going wrong. I
    have been lurking around here at the Asta Host forums with regard to login and user authentication
    scripts and I have got as far as this: - Starting a session - Registering a session variable -
    Using the variable to check if the user is authenticated or not. - Authenticating the user through
    MySQL database - Logging of the user, by setting the session variable to un-authenticated I have
    been able to achive the following things too that I think is not related to this proble....
  23. Photoshop Text Effect
    A photoshop text effect i found and thought was kool (1)
    Ok, well the other day i was making a video *dont ask why* and for the intro i wanted some pretty
    cool font, and font effects and so i experamented with Photoshop for a while until i came up with
    somthing i liked and i liked what i came up with so i think imma share it with people /biggrin.gif"
    style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> QUOTE First off i used
    the font Angryblue Available for download Here for PC's and Here For Mac's Now lets
    start off by getting a new or existing image, for existing image just open an exi....
  24. My FTP Quit Working
    haven't changed anything (10)
    Here's the error, I have not been able to connect in two days. CODE Command:    USER
    houdini Response:    331 User houdini OK. Password required Command:    PASS ********
    Response:    530 Authentication failed, sorry I went and even added a new account in the
    cPanel and it says I have an account, that one did not work either. I tried all that stuff with
    every account that I have and the same result, my phpMyAdmin works OK but I edit files with an ftp
    application built into my editor, those setting are correct so then I tried to use my regular F....
  25. Hottest Searched Keywords Over The Internet
    (7)
    I compiled this list consists of the most popular searched keywords using on some popular search
    engine: Google.com http://www.google.com/press/zeitgeist.html They also have a list by country,
    by topics ... AOL.com http://hot.aol.com/ This consists of a chart of CURRENT hottest search
    keyword, updated every several seconds Yahoo.com http://buzz.yahoo.com/ A pretty detail
    statistics MSN.com http://www.imagine-msn.com/insider/ Flash website, cool to look at Ask.com
    http://sp.ask.com/docs/about/jeevesiq.html ... It seems the hottest topic overall last month ....
  26. Neem: A Natural Treatment That Works?
    Neem trees - what scientists have found (12)
    One of my friends just sent me a link about the neem tree, which is the source of many cures and
    treatments in India (where he's from). We started talking about dental problems, which is one of
    the things that neem trees can treat, when he started telling me about the other things that
    scientists are discovering. Would you believe, for example, that extracts from this tree can be up
    to 100 percent effective as birth control? Or that it repels athlete's foot, psoriases, herpes,
    etc.? Yeah - I wouldn't believe it either if it weren't for the fact that sci....
  27. Some Facts I Found
    These are some facts I found (13)
    These are some facts I found. I've published them on a different site before, but I'm the
    rightsholder so I'll post them here too (little old, jan 8th 2005): ~Bored aren't you~
    *Montserrat's coastline is 40 km *1KB contains 1024bytes, not 1000bytes *The Isle Of Man has 1
    FM radio station *The world's largest tricycle's front wheel has a diameter of 4.67 m (15.3
    ft) and the back wheels measured 2.23 m (7.3 ft) across. The trike had an overall height of 7.13 m
    (23 ft 4 in). *Bill Curtis of Clacton-on-Sea, Essex, England, is acknowledged as t....
  28. MSN Searched Added To Dogpile Searcher
    (9)
    Well recently Msn Search was added to Dogpile searcher. http://www.dogpile.com this website
    provides people to search the major search engines(yahoo,google, msn search and ask jeeves). Try it
    out guys and post ur feedback, you're gonna like it.....
  29. Php : Variables Included Dont Work In Functions
    Variables from Included files dont work (4)
    Today, I came up with this strange PHP behaviour. Just wanted to know if anyone has any
    suggestions! I make a common variable/function file called config.php. I put in my generally
    used functions in it. Suppose this is my file // -----VARIABLES --- // $a=10,$b....
    // -----FUCTIONS--- // function doit() { print "A value is " . $a; } ?> Here, suppose we
    execute this file directly. Since A has a global scope, it does work perfectly. But if this same
    file is imported in another file say, mainfile.php // -----VARIABLES --- // $c,$....
  30. Vulnerability Was Found In All Major Browsers
    Spoofing Flaw affect IE, Firefox, Safari (20)
    According eWeek.com, a new vulnerability was found in all the major Web browsers ( IE, Firefox,
    Safari). This Spoofing Flaw can be exploited by malicious hackers to trick surfers into disclosing
    confidential information. QUOTE "The problem is that JavaScript dialog boxes do not display or
    include their origin, which allows a new window to open a prompt dialog box, which appears to be
    from a trusted site," Here is the place for you to test your broswer whether vulnerable or not.
    http://secunia.com/multiple_browsers_dialo...erability_test/ source: http://www.e....

    1. Looking for spliting, string, 3, variables, c, searched, net, havent, found

Searching Video's for spliting, string, 3, variables, c, searched, net, havent, found
Similar
String
Theory
Looking For
The Perfect
Cms... -
Haven't
found one
yet.
Strange
Ascii Code
22 Character
Detected In
Connection
String
A Lot Of
Infomation
About Cod4
Found On The
Internet
Check For
Occurence Of
Substring In
String
Php Long
Variables -
How do you
make them?
$_get
Issue
(urgent!
) - Get
variables
not working
Folder Of
Frontpage? -
Found A
Folder
Php Any
Variable In
String.
Sorting A
String
Vector
How To
Remove Query
String Using
Regular
Expressions
Major Flaw
Found In
.ani File
Through All
Major Ms
Operating
Systems
C# Tutorial
: Lesson 2 -
Variables
&
Operators
Php String
To Int
Typecasting
Pascal For
Beginners -
Part One -
The syntax,
variables,
input and
output
Check Out
This
Interesting
Information
I Found. -
Science
research.
Burn Iso To
Hd? - Found
on the net
it IS
possible but
none
explaining
HOW to do it
:-(
Quickly
Create Form
Variables -
simple form,
variable
creation,
referer
check, safe
guard
variables
Note: How To
Retrieve
Variables
From
Function To
Another
New Game -
Urban Rivals
- I found it
yesterday
3;
Found Some
Good Blogs
With Tons Of
Ebooks
User
Authenticati
on Session
Handling
Problems -
Authorizatio
n server
variables
not staying
across pages
Photoshop
Text Effect
- A
photoshop
text effect
i found and
thought was
kool
My FTP Quit
Working -
haven't
changed
anything
Hottest
Searched
Keywords
Over The
Internet
Neem: A
Natural
Treatment
That Works?
- Neem trees
- what
scientists
have found
Some Facts I
Found -
These are
some facts I
found
MSN Searched
Added To
Dogpile
Searcher
Php :
Variables
Included
Dont Work In
Functions -
Variables
from
Included
files dont
work
Vulnerabilit
y Was Found
In All Major
Browsers -
Spoofing
Flaw affect
IE, Firefox,
Safari
advertisement




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



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE