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

Thread: Function Error

  1. #1
    Join Date
    May 2008
    Posts
    14

    Unhappy Function Error

    Hallo all.

    I have a function that I got error when I compiled, I really do not know how to cope it.

    I have attach the code, and I was wondering if there is anyone would be able to help me..

    The error message is:
    error: stray '/342' in program
    stray '/200' in program
    ...
    error: no matching function far call to std::basic<char, std::char_traits<char>, ...

    It get error on this code

    int wordlen = x.find(" ");

    I really need help with that as my assignment is due soon.

    Thanks
    Attached Files Attached Files
    Last edited by glen_4455; May 9th, 2008 at 09:18 AM.

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Function Error

    What's the error?

  3. #3
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    Re: Function Error

    line 8: wordlen = x.find(“ “);
    does not contain valid characters.

  4. #4
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Function Error

    So you have some invalid characters (that are invisible) in your file. Go to the line that have a strange character. Type that line again on line before the offending line, mark the offending line and delete it.

    Edit: Yes Richard is right, you should use " not “ (probably cut&paste from word or similar editor?)
    Last edited by S_M_A; May 9th, 2008 at 09:28 AM.

  5. #5
    Join Date
    May 2008
    Posts
    14

    Unhappy Re: Function Error

    Hallo S_M_A,

    Thanks for your help, however, I am still have a problem with my codes.

    I make a menu program which is have 3 choices. 1st and 3rd choices in run well, whereas my 2nd choices it is not run well.

    The 2nd choices is pig-latin translation. Could you help me to see through the code and fix it up?

    I make 3 files, those are menu.h; menu.cpp; and menuApp.cpp
    Attached Files Attached Files

  6. #6
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    Re: Function Error

    what exactly is not working?

  7. #7
    Join Date
    May 2008
    Posts
    14

    Re: Function Error

    the one is not working is the pig latin..

    When I enter the string for example, "hello", the program does not give the pig-latin translation of it. (like no response..)

    I am really stuck with that...

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

    Re: Function Error

    Quote Originally Posted by glen_4455
    the one is not working is the pig latin..

    When I enter the string for example, "hello", the program does not give the pig-latin translation of it. (like no response..)

    I am really stuck with that...
    Please read this first:

    http://www.codeguru.com/forum/showpo...46&postcount=2

    Now tell us what exactly have you done to solve the problem.

    Have you used the debugger? If not, have you used output statements to see what is the problem? If you have done these, what results did you see? What was unexpected?

    All of these issues are first tackled by you. If you're learning programming, a mandatory part of programming is learning how to debug your own code. Just handing off code to us and saying "what's wrong" misses the whole point of learning the proper ways to find out for yourself the problems with code.

    I'm stating this, since I see too many posts where it is obviously a homework or homework-like assignment, where code is just handed off to us to "solve" if it doesn't run correctly, with no apparent effort on the original poster to attempt to diagnose the problem (no debug statements, no use of a debugger, no analysis as to what part of the code behaved differently than expected, etc.).

    If you have attempted to debug this, please state what you have done in this regard.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; May 9th, 2008 at 11:24 AM.

  9. #9
    Join Date
    May 2008
    Posts
    14

    Re: Function Error

    Thanks Paul,

    However, i do not know how to use debugger and never use it before. Wondering if you can show me to debug my program..

    I just compile my codes using g++ -Wall -g menuApp.cpp -o menuExe

    and then running gdb menuExe, and after that gdb run

    The program was running and when I select 2nd choices, it produces same output.. (nothing happens)

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

    Re: Function Error

    Quote Originally Posted by glen_4455
    However, i do not know how to use debugger and never use it before. Wondering if you can show me to debug my program..
    Even if you didn't know how to use a debugger, there are ways to solve these problems.

    What part of the code do you think is the problem? Wherever that is, you put output statements to see what the values of certain variables are. If they are not what you expected, then you place the output statements somewhere else, inspect the code by hand, or place more output statements to display what other variable values are. Things like outputting the value of loop counters, intermediate values, using the variout cout and printf() functions should be used.

    These are all things that you must know how to do, regardless of whether you know how to use the debugger or not. These old but successful techniques are used in any high-level language, whether it's C++, C, Pascal, Java, Fortran, or even COBOL. Even in some OS'es (like Windows), you have an OutputDebugString() available to show diagnostic messages.

    This is not aimed at you, but I get frustrated with the numerous number of new posters learning C++ that have shown absolutely no effort in doing the simplest things to debug their code -- not even a simple printf() statements to see what the value of various variables in their programs.

    When I first learned programming over 20 years ago, it was a requirement to solve your own problems, and only go to the tutors if you have shown what you've done to attempt to solve a problem that you were having (if the problem was still unsolved). No way could you say "here is my program, I run it, it does x when it should do y, what's wrong?"

    All of these techniques I mentioned are not the most modern (knowing how to use the debugger is the best way), but they do work. When the first interactive debuggers were introduced some time ago, it made all of the work of using printf()'s somewhat obsolete, but never so obsolete that they can not be used.

    Another side issue in seeing what effort you've made in solving the problem is to see if you were the one who wrote the code, and not just lifted it from a friend or a web-site. If you truly wrote the code, you should understand how each part of the code works or should work. If there is a bug, you know what parts of the code could be causing the problem. Many times people post code that their friend wrote, and they have no idea what's wrong. IMO, those types of posters shouldn't be helped, even if they are following the rule of posting code.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; May 9th, 2008 at 06:55 PM.

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