Thread: ascii to int

  1. #1
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72

    ascii to int

    Im reading data in from a file and using the values captured to manipulate shape placement in opengl. However, the data I get from the file is for example an 'ascii 0', so when i come to stick this into the function to position it, it doesnt understand that all it is is a 0. Ive seen a toascii() function when looking for an appropriate function, is there a similar function to convert ascii to ints?
    Last edited by gazsux; 02-20-2003 at 09:04 AM.

  2. #2
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    http://www.hh.se/stud/d98rolb/ansi/atoi().html
    Atoi() I think should make the trick

  3. #3
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72
    good sir, i could eat you... but i wont. ty

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    The FAQ. Maybe that will help you.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72
    ok, im still having problems. Ill describe what im doing.
    I have a text file that has a list of numbers and letters, this data im going to process and turn it into data to place opengl objects. the format of the data in the file is like:

    a001 b020

    I read these into an array using fgets.

    I evaluate the contents of the array, if it finds 'a' for example it then uses the next 3 numbers of the array as coordinates. in this case 0, 0, 1. Because im using the data individually the atoi() function i was told about isnt of much help as it takes one number and converts it and ignores the char data. I cant think of a way round this, any ideas?

  6. #6
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Code:
    char line[] = "a001 b020";
    
    int n1, n2, n3;
    
    n1 = line[1] - '0';
    n2 = line[2] - '0';
    n3 = line[3] - '0';

  7. #7
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72
    it worked! thats incredible! so the compiler presumably then is handling its own casting... *makes note* ty ty

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory leak
    By aruna1 in forum C++ Programming
    Replies: 3
    Last Post: 08-17-2008, 10:28 PM
  2. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Replies: 2
    Last Post: 03-24-2006, 08:36 PM
  5. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM