Thread: Starting over - Hopefully just a quick questions about C

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    44

    Starting over - Hopefully just a quick questions about C

    First off, my thanks for those who responded to my other post and advanced apologies for the "messiness" that happened with my first post.

    Now given that, I am have reduced my original problem to the following scenario.

    I read in some data from memory that is in ASCII format into an int_32 array.

    Then I need to compare/ treat some of the data as a string and some as a integer.


    My questions
    1. What will happen if I store ASCII into an integer array? How will be stored?
    For example I read "1234" from memory into an variable of int32_type x, what exactly will be stored in x?

    Thank you all again.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    It depends what you mean by 'store'

    You could take the numeric value of "1234" as 1234 and store that in your int32 variable.
    In hex, you would be looking at 4 bytes containing 00 00 04 D2

    Or you could store the 4-byte string in the integer, where each byte of the string maps to a byte within the int32.
    You might end up with 4 bytes containing 31 32 33 34
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    Could you post the actual code involved with this question? Then it will be easier to answer concretely. Specifically show how you are reading "1234" and how you are storing into an integer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 10-10-2014, 04:14 PM
  2. Quick pthread question - starting paused/suspended
    By NightWolf8800 in forum C Programming
    Replies: 3
    Last Post: 10-24-2009, 08:15 AM
  3. Replies: 10
    Last Post: 11-23-2007, 12:13 AM
  4. Starting C++ - questions
    By tauschke in forum C++ Programming
    Replies: 12
    Last Post: 12-12-2006, 06:45 AM
  5. 2 quick questions
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 11-29-2001, 12:32 AM

Tags for this Thread