This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Passing strings to a display routine

I have used the following code to send a display string to an RS232 port. It always worked in Keil Microvision2. Now in microvision5 it does not.

DispString (“Abcdefg\n”);

Void DispString ( unsigned char *gp) {
unsigned char i;
For (i=0; *(gp+i) != ‘\n’; i++) { putChar (*(gp+i) ); }
}

So why does the above DispString not work..??
I get no error messages.
However if I change (“Abcdefg”) to (‘Abcdefg’) I get error message …. > too many characters in character literal – extra leading characters ignored..
Can anyone explain and tell me what is the correct way in #5 (and maybe why it doesn't ?)
Thanks.
Bhal

  • What, exactly, do you mean by, "does not work" ?

    www.catb.org/.../smart-questions.html

    www.catb.org/.../smart-questions.html

    What debugging have you done to find what's happening?
    eg, have you stepped it in the debugger?

    if I change (“Abcdefg”) to (‘Abcdefg’) I get error message

    Of course you do - because that's not the correct way to write strings in 'C' !

    Your post shows different opening & closing quote characters - is that actually in your source code, or is it just an artefact of the forum?
    In your source code, you should just use the double-quote character - ASCII code 0x22

  • Sir,
    First, I do not see different opening and closing quotes ("..Your post shows different opening & closing quote characters - is that actually in your source code, or is it just an artefact of the forum?"..). I have looked carefully at my posted code..
    So maybe it is an artifact of the forum..
    Second, it is not true that single quotes "are not the correct way to write strings in C"....
    As a matter of fact, in the rest of this module,
    I have single quotes (e.g. putChar('a'); )and it works. i.e. I see the character a on the hyper terminal.
    But I want to be able to display messages which are multi character and each on is of different length and that is why i wrote this routine... It works in Microvision2 and 5 and on different processors...

    As for what debugging I have done, there is nothing showing up in the hyperterminal, and the single stepping shows it is stuck @ DispString(...) line.

    Perhaps you can explain why I am getting the error (... too many characters in character literal – extra leading characters ignored..)

    and what to do to fix it,

    rather than just say of course...

    Thanks. Bhal

  • Please find AND READ a tutorial on C programming. Your questions suggest that you would benefit from something for absolute beginners.

  • "it is not true that single quotes are not the correct way to write strings in C"

    Yes, it is - please study your 'C' textbook.

    "I have single quotes (e.g. putChar('a'); )and it works"

    That's a single character - not a string.
    They are different in 'C' - again, see your 'C' textbook.

    "it is stuck @ DispString(...) line"

    That's a function call. If it's stuck there, that means it is stuck somewhere in the code inside the function.

    So use the debugger to step into the function - and see what's happening ...

    "Perhaps you can explain why I am getting the error"

    If you do as suggested above, you will see the error for yourself.
    You will learn a lot more that way.

    Debugging is a key skill - you need to learn it: www.avrfreaks.net/.../2418156