Thread: intgers form a string

  1. #1
    Registered User
    Join Date
    Dec 2003

    intgers form a string

    All right, here it goes. I'm trying to get an intger from a string. FOr example I don't want "this" to be 4 intgers, I want to get AN intger from "this" Is there any easy way to do this?
    #define punkCow

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    What do you mean by "this"
    Store the 4 characters in an int in some way?

    int floogle = 't'<<24 | 'h' << 16 | 'i' << 8 | 's'
    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
    King of the Internet Fahrenheit's Avatar
    Join Date
    Oct 2001
    int whatevar = (int) 'this' ;

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    >int whatevar = (int) 'this' ;
    And this is supposed to be meaningful, how?

    >I'm trying to get an intger from a string.
    Be more specific. You can get an integer from a string many different ways, it depends on what you want to do with it.
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Dec 2001

    Do you mean something like this?
    union aryint
         char chrs[4];
         int    x;
    union aryint ai;

    ai.chrs[0] = 't';
    ai.chrs[1] = 'h';
    and so on.


    printf("The int is %d",ai.x);

    Is this what you want?
    You learn something new everyday.

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Another wild attempt at answering the non-specific question:
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please check my C++
    By csonx_p in forum C++ Programming
    Replies: 263
    Last Post: 07-24-2008, 09:20 AM
  2. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 03:40 AM
  3. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  5. Again Character Count, Word Count and String Search
    By client in forum C Programming
    Replies: 2
    Last Post: 05-09-2002, 11:40 AM