CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: char problems

  1. #1
    Join Date
    Aug 2001
    Posts
    29

    char problems

    before anything else, I'm sitting on this kind
    system: SunOS magna 5.8 Generic_108528-12 sun4u sparc SUNW,Ultra-5_10
    people seem to wanna know that.

    problem-> warning: subscript has type `char'

    function declaration looks like this..

    void do_password( CHAR_DATA *ch, char *argument )




    the lines wich the compiler complains about looks like this.

    while ( isspace(*argument) )
    {
    argument++;
    }




    I dont want to have that warning, how do I get rid of it?

    MvH Mattias "Nallen" Holmström(Sweden,[email protected])

  2. #2
    Join Date
    Mar 2002
    Location
    Israel
    Posts
    187

    Re: char problems

    Hi Mattias,

    try to use this function:

    template<class E>
    bool isspace(E c, const locale& loc) const;




    or make shure that isspace, defined in Your ctype.h (i guess) expect char, and not int.


    In the future computer's weight will not exceed 1.5 ton.
    (Popular Mechanics, 1949)

  3. #3
    Join Date
    Aug 2001
    Posts
    29

    Re: char problems

    ok, I dont understand any of what you have writen and dont know how
    to implement it.

    I have looked a little at ctype.h and I cant say that I understand any of that
    either... here follows a summary of the function isspace() wich I found
    in this systems help section.

    Summary:
    isspace()
    Tests for any space, tab, carriage-return, newline,
    vertical-tab or form-feed (standard white-space char-
    acters) or for one of the current locale-defined set
    of characters for which isalnum() is false. In the C
    locale, isspace() returns true only for the standard
    white-space characters.

    please help me make a function wich does the same thing as isspace but
    is of type char instead of int. I'm a newbie programmer trying to compile a
    mud(www.rom.org) and removing any warnings that come my way. please...


    MvH Mattias "Nallen" Holmström(Sweden,[email protected])

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: char problems

    What is the prototype of isspace?

    The usual argument type to isspace is int. All you need to do is promote the value to an integer.

    isspace((int)*argument);



    Regards,

    Paul McKenzie



  5. #5
    Join Date
    Mar 2002
    Location
    Israel
    Posts
    187

    Re: char problems

    Ok,

    if You need to define what should be a white space character:

    The myIsspace(char) could look like:

    #define GET_MAP(map) \
    map['\t' >> 3] |= (1 << ('\t' & 7)); \
    map['\n' >> 3] |= (1 << ('\n' & 7))
    /* Add here entries for other white characters*/

    #define MAP_SIZE 32

    int myIsspace(char ch)
    {
    int li, loopMax = MAP_SIZE / sizeof(li);
    char map[MAP_SIZE];
    for(li = 0; li < loopMax; li++)
    map[li] = 0;
    GET_MAP(map);
    return map[ch >> 3] & (1 << (ch & 7));
    }




    You are wellcome to ask questions about.

    In the future computer's weight will not exceed 1.5 ton.
    (Popular Mechanics, 1949)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured