problem with char * and unsigned long

This is a discussion on problem with char * and unsigned long within the C++ Programming forums, part of the General Programming Boards category; Code: unsigned long lPid; lPid = argv[0]; funcs.h(453) : error C2440: '=' : cannot convert from 'char *' to 'unsigned ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    13

    Unhappy problem with char * and unsigned long

    Code:
    	unsigned long lPid;
    
    	lPid = argv[0];

    funcs.h(453) : error C2440: '=' : cannot convert from 'char *' to 'unsigned long'
    This conversion requires a reinterpret_cast, a C-style cast or function-style cast


    argv[0] cant be changed to any other type.

    is there any way to do convert?
    Mouse

  2. #2
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    I think
    Code:
    unsigned long lPid;
    (char*)lPid=argv[0]
    or
    Code:
    char* lPid;
    lPid=argv[0]
    (unsigned long)lPid (Whatever code goes here)
    at least I think that. I would play around with casting.
    But I wouldnt see why you would do that.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    to convert a string to long use strtol.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    Don't cast it, that won't convert the string to its corresponding integer value.

    To convert a string to a long, see the FAQ. The short answer is to use a stringstream, strtol or atoi.

  5. #5
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    You probably want argv[1].
    Code:
    	stringstream s;
    	unsigned long lPid;
    
    	s << argv[1];
    	s >> lPid;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  3. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 03:49 PM
  4. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 06:59 AM

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