CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2010
    Posts
    25

    Problem with strchr

    I'm trying to manage this code to work:

    char * a = "b";
    char * b = "abc";
    strchr(a,b);

    but it gives me the error:
    error C2665: 'strchr' : none of the 2 overloads could convert all the argument types

    What can cause this? and how can this be solved?

    Thanks.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Problem with strchr

    Well, the cause is pretty obvious: the second parameter must be of the type int or unsigned int
    You should better have described what you were trying to accomplish rather than complain on this error message.
    Victor Nijegorodov

  3. #3
    Join Date
    May 2010
    Posts
    25

    Re: Problem with strchr

    well that doesn't make sense to me then.
    I'm trying to find the first occurance of "b" in the string "abc", and if it is there then I need to know where exactly.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Problem with strchr

    Then why don't you want to write it according to your description:
    Code:
    strchr("abc", 'b');
    Note that you are searching for a single character (therefore an apostrophe is expected), not for some string (in which case the quotation mark is used)
    Victor Nijegorodov

  5. #5
    Join Date
    May 2010
    Posts
    25

    Re: Problem with strchr

    Thanks! Is there a function that looks for a string inside a string?

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Problem with strchr

    If you couls use MFC - then CString::Find
    Otherwise - have a look at STL std::string
    Victor Nijegorodov

  7. #7
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Problem with strchr

    or strstr()

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