Thread: How to convert string containing numbers (separated by chars) to an int?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Registered User
    Join Date
    Nov 2012
    Posts
    16
    Since I'm taking these values from an array of strings, I should of course copy and parse them into an array of int's, so it would look more like this:

    Code:
    char new_string[lineNo];
    int int_conversion[lineNo];
    
    for(lineNo = 1; lineNo < MAX_LINES; lineNo++)
    {  
       if(isdigit(data[lineNo].variable))
           {
              strcpy(new_string[lineNo], data[lineNo].variable;
           }
    }
    
    int_conversion[lineNo] = atoi( new_string[lineNo] );
    ..or am I missing/skipping some steps?
    Last edited by kensing; 11-26-2012 at 11:36 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. convert set of chars into double
    By doia in forum C Programming
    Replies: 13
    Last Post: 06-15-2010, 10:25 AM
  2. Convert Integer to Hex in an array of chars
    By anasimtiaz in forum C Programming
    Replies: 12
    Last Post: 07-22-2009, 05:29 PM
  3. Replies: 2
    Last Post: 03-15-2009, 03:17 PM
  4. Replies: 2
    Last Post: 10-22-2008, 07:20 PM
  5. chars and numbers in C++
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 01-10-2002, 05:49 PM