char syntax question

Discussion in 'C++' started by Frits JK, Jun 24, 2004.

  1. Frits JK

    Frits JK Guest

    Please help.



    I have to make a little change to a DLL , original there was a static char
    szIPAddr, and I want to make it variable. Unfortunately I am not good enough
    with C++ syntax







    original syntax was :

    //-----------------------------------------------------------------



    extern "C" int PASCAL EXPORT ReadMidi( void )



    {



    static char szIPAddr[32] = { "10.0.0.4" } ;

    static struct sockaddr_in sa ;

    sa.sin_addr.S_un.S_addr = inet_addr (szIPAddr) ;







    Desired syntax

    //------------------------------------------------------------------



    extern "C" int PASCAL EXPORT ReadMidi( char szIPAddr )



    {



    static struct sockaddr_in sa ;

    sa.sin_addr.S_un.S_addr = inet_addr (szIPAddr) ;







    this gives error :

    : error C2664: 'inet_addr' : cannot convert parameter 1 from 'char' to
    'const char *'

    Conversion from integral type to pointer type requires reinterpret_cast,
    C-style cast or function-style cast







    Regards,

    Frits Janse Kok
     
    Frits JK, Jun 24, 2004
    #1
    1. Advertising

  2. Frits JK wrote:
    > Please help.
    >
    > I have to make a little change to a DLL , original there was a static char
    > szIPAddr, and I want to make it variable. Unfortunately I am not good enough
    > with C++ syntax
    >
    > original syntax was :
    >
    > //-----------------------------------------------------------------
    > extern "C" int PASCAL EXPORT ReadMidi( void )
    > {
    > static char szIPAddr[32] = { "10.0.0.4" } ;

    Note that the above variable is an array of characters,
    not just a single one.


    > static struct sockaddr_in sa ;
    > sa.sin_addr.S_un.S_addr = inet_addr (szIPAddr) ;
    >
    > Desired syntax
    >
    > //------------------------------------------------------------------
    > extern "C" int PASCAL EXPORT ReadMidi( char szIPAddr )

    This should be:
    extern "C" int PASCAL EXPORT ReadMidi(char * szIPAddr)
    Note the location of '*'.


    > {
    > static struct sockaddr_in sa ;
    > sa.sin_addr.S_un.S_addr = inet_addr (szIPAddr) ;
    >
    > Regards,
    >
    > Frits Janse Kok
    >
    >



    --
    Thomas Matthews

    C++ newsgroup welcome message:
    http://www.slack.net/~shiva/welcome.txt
    C++ Faq: http://www.parashift.com/c -faq-lite
    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.learn.c-c++ faq:
    http://www.raos.demon.uk/acllc-c /faq.html
    Other sites:
    http://www.josuttis.com -- C++ STL Library book
     
    Thomas Matthews, Jun 24, 2004
    #2
    1. Advertising

  3. Frits JK

    Frits JK Guest

    That works !!
    Thank you very much for the quick reaction.

    Frits Janse Kok


    "Thomas Matthews" <> schreef in
    bericht news:IQCCc.3697$...
    > Frits JK wrote:
    > > Please help.
    > >
    > > I have to make a little change to a DLL , original there was a static

    char
    > > szIPAddr, and I want to make it variable. Unfortunately I am not good

    enough
    > > with C++ syntax
    > >
    > > original syntax was :
    > >
    > > //-----------------------------------------------------------------
    > > extern "C" int PASCAL EXPORT ReadMidi( void )
    > > {
    > > static char szIPAddr[32] = { "10.0.0.4" } ;

    > Note that the above variable is an array of characters,
    > not just a single one.
    >
    >
    > > static struct sockaddr_in sa ;
    > > sa.sin_addr.S_un.S_addr = inet_addr (szIPAddr) ;
    > >
    > > Desired syntax
    > >
    > > //------------------------------------------------------------------
    > > extern "C" int PASCAL EXPORT ReadMidi( char szIPAddr )

    > This should be:
    > extern "C" int PASCAL EXPORT ReadMidi(char * szIPAddr)
    > Note the location of '*'.
    >
    >
    > > {
    > > static struct sockaddr_in sa ;
    > > sa.sin_addr.S_un.S_addr = inet_addr (szIPAddr) ;
    > >
    > > Regards,
    > >
    > > Frits Janse Kok
    > >
    > >

    >
    >
    > --
    > Thomas Matthews
    >
    > C++ newsgroup welcome message:
    > http://www.slack.net/~shiva/welcome.txt
    > C++ Faq: http://www.parashift.com/c -faq-lite
    > C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    > alt.comp.lang.learn.c-c++ faq:
    > http://www.raos.demon.uk/acllc-c /faq.html
    > Other sites:
    > http://www.josuttis.com -- C++ STL Library book
    >
     
    Frits JK, Jun 24, 2004
    #3
  4. Frits JK wrote:
    > Please help.
    >
    >
    >
    > I have to make a little change to a DLL , original there was a static char
    > szIPAddr, and I want to make it variable. Unfortunately I am not good enough
    > with C++ syntax


    If you're not "good enough" (and this 'char' business is really very
    basic stuff), you should not attempt changing a DLL... Just a thought.

    >
    >
    >
    >
    >
    >
    >
    > original syntax was :
    >
    > //-----------------------------------------------------------------
    >
    >
    >
    > extern "C" int PASCAL EXPORT ReadMidi( void )
    >
    >
    >
    > {
    >
    >
    >
    > static char szIPAddr[32] = { "10.0.0.4" } ;
    >
    > static struct sockaddr_in sa ;
    >
    > sa.sin_addr.S_un.S_addr = inet_addr (szIPAddr) ;
    >
    >
    >
    >
    >
    >
    >
    > Desired syntax
    >
    > //------------------------------------------------------------------
    >
    >
    >
    > extern "C" int PASCAL EXPORT ReadMidi( char szIPAddr )


    Make it

    extern "C" int PASCAL EXPORT ReadMidi( char const * szIPAddr )

    >
    >
    >
    > {
    >
    >
    >
    > static struct sockaddr_in sa ;
    >
    > sa.sin_addr.S_un.S_addr = inet_addr (szIPAddr) ;
     
    Victor Bazarov, Jun 24, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wwj
    Replies:
    7
    Views:
    558
  2. wwj
    Replies:
    24
    Views:
    2,521
    Mike Wahler
    Nov 7, 2003
  3. Ben Pfaff
    Replies:
    5
    Views:
    480
    Tristan Miller
    Jan 17, 2004
  4. Steffen Fiksdal

    void*, char*, unsigned char*, signed char*

    Steffen Fiksdal, May 8, 2005, in forum: C Programming
    Replies:
    1
    Views:
    590
    Jack Klein
    May 9, 2005
  5. lovecreatesbeauty
    Replies:
    1
    Views:
    1,064
    Ian Collins
    May 9, 2006
Loading...

Share This Page