Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Prepend a letter to a char array using ASCII

Prepend a letter to a char array using ASCII

Scheduled Pinned Locked Moved C / C++ / MFC
iosgame-devdata-structureshelptutorial
3 Posts 3 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brent Lamborn
    wrote on last edited by
    #1

    This is the functin I'm working with: //Load skills from skills.txt void CJobQueueSimulatorView::LoadSkills() { int numItems = m_skills.GetCount(); for(int k = 0; k < numItems; k++) { m_skills.DeleteString(0); } char next[25]; fstream fin(strCurrType + "_skills.txt", ios::in); if(!fin) { MessageBox("Could not open skills file!", "File Error", MB_ICONEXCLAMATION); } else while(fin >> next) m_skills.AddString(next); fin.close(); } What I would like to do is prepend a letter to each line I read from my text file. This would give me an I.D. that I can associate with each "skill". m_skills is a list box control variable. I don't want the letter code to be saved in the text file. I would like it to be assigned as the lines are taken from file and put into the list box. This would prevent users from assigning skills the same "I.D". Also, later when they add skills to the list, it would automatically assign an "I.D" I'm thinking the way to do it is with ASCII but I'm dumb:confused: and don't know how to do it. Anyone have a good idea of how to do it? (Sorry for the sloppy formnatting above. Things didn't copy over that well) "It has become appallingly obvious that our technology has exceeded our humanity." - Albert Einstein (1879-1955) "I think there is a world market for maybe five computers." - Thomas Watson (1874-1956), Chairman of IBM, 1943 "640K ought to be enough for anybody." - Bill Gates (1955-), in 1981 "Half this game is ninety percent mental." - Yogi Berra

    H D 2 Replies Last reply
    0
    • B Brent Lamborn

      This is the functin I'm working with: //Load skills from skills.txt void CJobQueueSimulatorView::LoadSkills() { int numItems = m_skills.GetCount(); for(int k = 0; k < numItems; k++) { m_skills.DeleteString(0); } char next[25]; fstream fin(strCurrType + "_skills.txt", ios::in); if(!fin) { MessageBox("Could not open skills file!", "File Error", MB_ICONEXCLAMATION); } else while(fin >> next) m_skills.AddString(next); fin.close(); } What I would like to do is prepend a letter to each line I read from my text file. This would give me an I.D. that I can associate with each "skill". m_skills is a list box control variable. I don't want the letter code to be saved in the text file. I would like it to be assigned as the lines are taken from file and put into the list box. This would prevent users from assigning skills the same "I.D". Also, later when they add skills to the list, it would automatically assign an "I.D" I'm thinking the way to do it is with ASCII but I'm dumb:confused: and don't know how to do it. Anyone have a good idea of how to do it? (Sorry for the sloppy formnatting above. Things didn't copy over that well) "It has become appallingly obvious that our technology has exceeded our humanity." - Albert Einstein (1879-1955) "I think there is a world market for maybe five computers." - Thomas Watson (1874-1956), Chairman of IBM, 1943 "640K ought to be enough for anybody." - Bill Gates (1955-), in 1981 "Half this game is ninety percent mental." - Yogi Berra

      H Offline
      H Offline
      HJo
      wrote on last edited by
      #2

      strcat() example from MSDN: /* STRCPY.C: This program uses strcpy * and strcat to build a phrase. */ #include #include void main( void ) { char string[80]; strcpy( string, "Hello world from " ); strcat( string, "strcpy " ); strcat( string, "and " ); strcat( string, "strcat!" ); printf( "String = %s\n", string ); } Output: String = Hello world from strcpy and strcat!

      1 Reply Last reply
      0
      • B Brent Lamborn

        This is the functin I'm working with: //Load skills from skills.txt void CJobQueueSimulatorView::LoadSkills() { int numItems = m_skills.GetCount(); for(int k = 0; k < numItems; k++) { m_skills.DeleteString(0); } char next[25]; fstream fin(strCurrType + "_skills.txt", ios::in); if(!fin) { MessageBox("Could not open skills file!", "File Error", MB_ICONEXCLAMATION); } else while(fin >> next) m_skills.AddString(next); fin.close(); } What I would like to do is prepend a letter to each line I read from my text file. This would give me an I.D. that I can associate with each "skill". m_skills is a list box control variable. I don't want the letter code to be saved in the text file. I would like it to be assigned as the lines are taken from file and put into the list box. This would prevent users from assigning skills the same "I.D". Also, later when they add skills to the list, it would automatically assign an "I.D" I'm thinking the way to do it is with ASCII but I'm dumb:confused: and don't know how to do it. Anyone have a good idea of how to do it? (Sorry for the sloppy formnatting above. Things didn't copy over that well) "It has become appallingly obvious that our technology has exceeded our humanity." - Albert Einstein (1879-1955) "I think there is a world market for maybe five computers." - Thomas Watson (1874-1956), Chairman of IBM, 1943 "640K ought to be enough for anybody." - Bill Gates (1955-), in 1981 "Half this game is ninety percent mental." - Yogi Berra

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        char next[25]; CString str; ... while(fin >> next) { str = some_unique_identifier + next; m_skills.AddString(str); }

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups