Help with casting

This is a discussion on Help with casting within the C++ Programming forums, part of the General Programming Boards category; I am writting a validation program. this program receives a string from another program. this string contains a number like ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    10

    Unhappy Help with casting

    I am writting a validation program.

    this program receives a string from another program. this string contains a number like 123.

    what my program has to do is convert this string into a short and validate it. i have to make sure the number is between 1-300.
    after i validated it i have to pass it to another function.

    does anyone know how to convert the string into a short???

    thanks
    #include <iostream.h>
    void main(void){
    char t[7] = "Thanks";

    cout<< t <<endl;
    }

  2. #2
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    use atoi... converts strings to integers...
    hasafraggin shizigishin oppashigger...

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    You can use atoi() to return an int. To turn that int into a short you can do this....

    char array[5]="1234";
    int num=atoi(array);
    short snum=num & 0xffff;
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Casting
    By morvick in forum C++ Programming
    Replies: 2
    Last Post: 06-17-2007, 11:06 PM
  2. Casting Question (I think)
    By fayte in forum C Programming
    Replies: 6
    Last Post: 03-08-2006, 04:31 PM
  3. casting the system exstracted date into seperate ints
    By bazzano in forum C Programming
    Replies: 1
    Last Post: 08-30-2005, 12:17 AM
  4. Type casting
    By Lionmane in forum C Programming
    Replies: 28
    Last Post: 08-20-2005, 02:16 PM
  5. question about casting pointers/other types also??
    By newbie02 in forum C++ Programming
    Replies: 3
    Last Post: 08-07-2003, 05:01 AM

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