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. locating memory- easy(char[])

locating memory- easy(char[])

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestionperformancehelp
4 Posts 3 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.
  • S Offline
    S Offline
    SilverShalkin
    wrote on last edited by
    #1

    if you declare the amount of info that you want to store in a char like... char ID[10]; that would mean that id has 10 slots + \0; right? now, if i would want to print out all the info from char ID... wouldnt i just.. cout << ID;? and if you wrote: cout << ID[2]; you would get the third memory slot, right? why cant i set M_ID = ID? M_ID is [10] and so is ID. bool ID::SetID(char ID[10]) { M_ID = ID return true; } i get an error when i put this in, and the only way i get rid of it is if i make: ID[]; and within the [] i would have to have a number. but i want all of ID = M_ID.., what do i do? what do i put in the []? also... if there is a good tutorial that teaches how to compare data, and all the little detail of do what im trying to do, please make note of it. Thanks! ~SilverShalkin :rose: ps... I started this message like 1-2 hours ago, and kept jumping back to my code and trying new things... so if the message is unclear about my mainpoint "question" just tell me, and i will refrase it in a more understandable way :)

    M 1 Reply Last reply
    0
    • M Michael Dunn

      A C-style string is stored in a char array, however a char array is not magically a string. You must ensure that the array is properly null-terminated. The way you do that is to always use the string functions when manipulating strings. SilverShalkin wrote: char ID[10]; that would mean that id has 10 slots + \0; right? No, that declares a 10-character array. Again, it's not magically a string. It just contains 10 characters. SilverShalkin wrote: now, if i would want to print out all the info from char ID... wouldnt i just.. cout << ID;? As long as ID is null-terminted, that's correct. SilverShalkin wrote: bool ID::SetID(char ID[10]) { M_ID = ID; } That is an error because you can't assign strings (or any arrays) with =. You copy a string with strcpy(). --Mike-- Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines! My really out-of-date homepage Sonork - 100.10414 AcidHelm

      S Offline
      S Offline
      SilverShalkin
      wrote on last edited by
      #2

      thanks! i was using strcpy() but then switched over because things werent working... ill try it again. Any tutorials? Thanks again! ~SilverShalkin :rose:

      A 1 Reply Last reply
      0
      • S SilverShalkin

        if you declare the amount of info that you want to store in a char like... char ID[10]; that would mean that id has 10 slots + \0; right? now, if i would want to print out all the info from char ID... wouldnt i just.. cout << ID;? and if you wrote: cout << ID[2]; you would get the third memory slot, right? why cant i set M_ID = ID? M_ID is [10] and so is ID. bool ID::SetID(char ID[10]) { M_ID = ID return true; } i get an error when i put this in, and the only way i get rid of it is if i make: ID[]; and within the [] i would have to have a number. but i want all of ID = M_ID.., what do i do? what do i put in the []? also... if there is a good tutorial that teaches how to compare data, and all the little detail of do what im trying to do, please make note of it. Thanks! ~SilverShalkin :rose: ps... I started this message like 1-2 hours ago, and kept jumping back to my code and trying new things... so if the message is unclear about my mainpoint "question" just tell me, and i will refrase it in a more understandable way :)

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        A C-style string is stored in a char array, however a char array is not magically a string. You must ensure that the array is properly null-terminated. The way you do that is to always use the string functions when manipulating strings. SilverShalkin wrote: char ID[10]; that would mean that id has 10 slots + \0; right? No, that declares a 10-character array. Again, it's not magically a string. It just contains 10 characters. SilverShalkin wrote: now, if i would want to print out all the info from char ID... wouldnt i just.. cout << ID;? As long as ID is null-terminted, that's correct. SilverShalkin wrote: bool ID::SetID(char ID[10]) { M_ID = ID; } That is an error because you can't assign strings (or any arrays) with =. You copy a string with strcpy(). --Mike-- Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines! My really out-of-date homepage Sonork - 100.10414 AcidHelm

        S 1 Reply Last reply
        0
        • S SilverShalkin

          thanks! i was using strcpy() but then switched over because things werent working... ill try it again. Any tutorials? Thanks again! ~SilverShalkin :rose:

          A Offline
          A Offline
          Alexandru Savescu
          wrote on last edited by
          #4

          SilverShalkin wrote: Any tutorials? Any C beginners book. And you can look up in MSDN if you have any problems. Best regards, Alexandru Savescu

          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