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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. values not showing up in array

values not showing up in array

Scheduled Pinned Locked Moved C / C++ / MFC
helpdata-structuressecuritydebuggingtutorial
5 Posts 2 Posters 0 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.
  • J Offline
    J Offline
    John Aldrich
    wrote on last edited by
    #1

    I'm writting code which fills up a character array with numeric values which will later be converted in to character values for use with an encryption function. The problem I'm having is that the array values do not seem to be making it into the array, and I'm pulling my hair out trying to figure what's going wrong. Source Code Follows

    // make a 256 element alphanumeric string
    
    int nElementCount = 0;
    int nElementValue = 0;
    
    char szStringArray\[\] = "\\0";
    
    	
    	// length check
    
    	while ( nElementCount < 255 )
    	
    	{
    	
    		szStringArray\[nElementCount\] = nElementValue;
    		
    		// post increment so that we go to the next
    		// element number and value pair.
    
    		nElementCount++;
    		nElementValue++;
    	
    	}
    
    // debug message
    //
    // should list the entire range of elements in the array
    
    MessageBox(NULL, szStringArray, "Debug Message", MB\_OK);
    

    As can see the code is pretty straight forward, but I just seem to not be able to get values into the array. It's probably something simple that I'm missing due to newbie-itis. If someone could point out what's wrong with my code and how to fix it, I'd appreciate it. It's good to see kids turning their minds to wholesum activities such as programming, instead of wasting their lives in the hedonistic disciplines of Sex, Drugs, & Rock & Roll... or Sex with Drugs, or Sex with Rocks while Rolling in Drugs, or whatever new-fangled perversions you little monsters have thought up now... [Shog9 on Kid Programmers]

    N 2 Replies Last reply
    0
    • J John Aldrich

      I'm writting code which fills up a character array with numeric values which will later be converted in to character values for use with an encryption function. The problem I'm having is that the array values do not seem to be making it into the array, and I'm pulling my hair out trying to figure what's going wrong. Source Code Follows

      // make a 256 element alphanumeric string
      
      int nElementCount = 0;
      int nElementValue = 0;
      
      char szStringArray\[\] = "\\0";
      
      	
      	// length check
      
      	while ( nElementCount < 255 )
      	
      	{
      	
      		szStringArray\[nElementCount\] = nElementValue;
      		
      		// post increment so that we go to the next
      		// element number and value pair.
      
      		nElementCount++;
      		nElementValue++;
      	
      	}
      
      // debug message
      //
      // should list the entire range of elements in the array
      
      MessageBox(NULL, szStringArray, "Debug Message", MB\_OK);
      

      As can see the code is pretty straight forward, but I just seem to not be able to get values into the array. It's probably something simple that I'm missing due to newbie-itis. If someone could point out what's wrong with my code and how to fix it, I'd appreciate it. It's good to see kids turning their minds to wholesum activities such as programming, instead of wasting their lives in the hedonistic disciplines of Sex, Drugs, & Rock & Roll... or Sex with Drugs, or Sex with Rocks while Rolling in Drugs, or whatever new-fangled perversions you little monsters have thought up now... [Shog9 on Kid Programmers]

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      John Aldrich wrote: char szStringArray[] = "\0"; ?????!!!!!!!!!????????!!!!!!!!!! :wtf: :wtf: :wtf:


      Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

      1 Reply Last reply
      0
      • J John Aldrich

        I'm writting code which fills up a character array with numeric values which will later be converted in to character values for use with an encryption function. The problem I'm having is that the array values do not seem to be making it into the array, and I'm pulling my hair out trying to figure what's going wrong. Source Code Follows

        // make a 256 element alphanumeric string
        
        int nElementCount = 0;
        int nElementValue = 0;
        
        char szStringArray\[\] = "\\0";
        
        	
        	// length check
        
        	while ( nElementCount < 255 )
        	
        	{
        	
        		szStringArray\[nElementCount\] = nElementValue;
        		
        		// post increment so that we go to the next
        		// element number and value pair.
        
        		nElementCount++;
        		nElementValue++;
        	
        	}
        
        // debug message
        //
        // should list the entire range of elements in the array
        
        MessageBox(NULL, szStringArray, "Debug Message", MB\_OK);
        

        As can see the code is pretty straight forward, but I just seem to not be able to get values into the array. It's probably something simple that I'm missing due to newbie-itis. If someone could point out what's wrong with my code and how to fix it, I'd appreciate it. It's good to see kids turning their minds to wholesum activities such as programming, instead of wasting their lives in the hedonistic disciplines of Sex, Drugs, & Rock & Roll... or Sex with Drugs, or Sex with Rocks while Rolling in Drugs, or whatever new-fangled perversions you little monsters have thought up now... [Shog9 on Kid Programmers]

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #3

        Sorry for the prev reply, but I just watched ugggh Event Horizon on TV [roughly 40% of the latter 60%] and am still not fully normal yet :-( John Aldrich wrote: char szStringArray[] = "\0"; Change that to :- char szStringArray[256] ; Nish


        Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

        J 1 Reply Last reply
        0
        • N Nish Nishant

          Sorry for the prev reply, but I just watched ugggh Event Horizon on TV [roughly 40% of the latter 60%] and am still not fully normal yet :-( John Aldrich wrote: char szStringArray[] = "\0"; Change that to :- char szStringArray[256] ; Nish


          Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

          J Offline
          J Offline
          John Aldrich
          wrote on last edited by
          #4

          Just made that change. My dubug statement is still showing no values in the array. is there another check I can do to see if there actually are values? It's good to see kids turning their minds to wholesum activities such as programming, instead of wasting their lives in the hedonistic disciplines of Sex, Drugs, & Rock & Roll... or Sex with Drugs, or Sex with Rocks while Rolling in Drugs, or whatever new-fangled perversions you little monsters have thought up now... [Shog9 on Kid Programmers]

          N 1 Reply Last reply
          0
          • J John Aldrich

            Just made that change. My dubug statement is still showing no values in the array. is there another check I can do to see if there actually are values? It's good to see kids turning their minds to wholesum activities such as programming, instead of wasting their lives in the hedonistic disciplines of Sex, Drugs, & Rock & Roll... or Sex with Drugs, or Sex with Rocks while Rolling in Drugs, or whatever new-fangled perversions you little monsters have thought up now... [Shog9 on Kid Programmers]

            N Offline
            N Offline
            Nish Nishant
            wrote on last edited by
            #5

            John Aldrich wrote: Just made that change. My dubug statement is still showing no values in the array. is there another check I can do to see if there actually are values? That's because nElementValue is initially 0 and you assign it as the first value of your array. Strings are 0-terminated. Thus your MessageBox won't come up because it sees a null string. Start with nElementValue = 32. 32 is space and 32 upwards is legal characters and stop at 127. otherwise you have all kinds of funny control chasracters which might end up as boxes in the text on screen or might have other bad side effects. Nish


            Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

            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