Thread: type checking

  1. #1
    Registered User white's Avatar
    Join Date
    Nov 2004
    Posts
    39

    type checking

    Basically I have a file with random words and some double values; there is no apparent structure in the structure I've written the code to read the file and pass it into an array.
    So now Is there a way to check whether each element in the array contain characters or numbers?

    The goal is to seperate the numeric values and flush them into a file.
    ----------------

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    You can easily test a string to see if it's numeric. If they're floating-point values, the easiest way is to try to convert the string to a double with strtod:
    Code:
    char *end;
    double d = strtod ( line, &end );
    
    if ( end != line && *end != '\0' ) {
      /* Not a number */
    }
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you check what is wrong with this code
    By Ron in forum C++ Programming
    Replies: 4
    Last Post: 08-01-2008, 10:59 PM
  2. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  3. Data type checking?
    By Trauts in forum C++ Programming
    Replies: 2
    Last Post: 02-09-2003, 05:24 PM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  5. Type checking
    By Araenor in forum C Programming
    Replies: 10
    Last Post: 08-29-2001, 12:47 AM