Need Help

Discussion in 'C' started by bashamsc, Jan 1, 2008.

  1. bashamsc

    bashamsc New Member

    Joined:
    May 22, 2007
    Messages:
    51
    Likes Received:
    7
    Trophy Points:
    0
    Location:
    chennai
    Suppose i have a file in which i have strings and integers

    I want read that file and wants to store in an array.

    My problem is how to differciate whether the read one is string or integer.

    Because i need to manupulate the data .
     
  2. technosavvy

    technosavvy New Member

    Joined:
    Jan 2, 2008
    Messages:
    52
    Likes Received:
    0
    Trophy Points:
    0
    if the file you are reading only contains strings and numbers then u can easily do it...(i.e. there are no alphanumeric words in the file)

    in this case
    1) read every word from the file as a string ...
    2) convert the string into a number using atof
    3) if the input is a string the return value of the function atof is 0 otherwise the return value will be
    the number converted.
    4) put a check in your program for the return value of the function and you are done
     
  3. bashamsc

    bashamsc New Member

    Joined:
    May 22, 2007
    Messages:
    51
    Likes Received:
    7
    Trophy Points:
    0
    Location:
    chennai
    I want in c++ not in c.
     
  4. technosavvy

    technosavvy New Member

    Joined:
    Jan 2, 2008
    Messages:
    52
    Likes Received:
    0
    Trophy Points:
    0
    even if u want in C++ ...atof will work ...

    do u have any other issue..do let me know ..
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice