type checking

This is a discussion on type checking within the C Programming forums, part of the General Programming Boards category; Basically I have a file with random words and some double values; there is no apparent structure in the structure ...

  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,796
    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, 11:59 PM
  2. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 05: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, 07:49 PM
  5. Type checking
    By Araenor in forum C Programming
    Replies: 10
    Last Post: 08-29-2001, 01:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21