Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 4 months ago.
print an Ascii
can someone help me how to increment an ASCII character? i feel dumb.
my code below.
char a = 'a'; if (_ps3report->PressureCircle > 0 ) { printf("output: %c ", a ); } a++;
2 Answers
11 years, 4 months ago.
Hi kilo, your code looks fine, perhaps something else in the code is making it fail?, I probe this code to show in my lcd the first three letters and works fine:
#include "mbed.h" #include "C12832_lcd.h" C12832_LCD lcd; int main() { char a='a'; while(1) { lcd.printf("Character: %c\n",a); if(a=='c') break; a++; } }
Greetings
11 years, 4 months ago.
You need to do somethinl like this, assuming you want to display a, b, c ..
.. char ascii = 'a'; // print out the 'a' lcd.printf ("First time $c .. \r\n", ascii); // increment value .. ascii ++; lcd.printf ("Inced by one .. %c", ascii); lcd.printf ("Inced by one again .. %c", ++ascii); // inc before use lcd.printf ("Inced by one .. %c", ascii++); // inc after use .. lcd.printf ("Inced by one .. %c", ascii++); // inc after use ..
hope that was usefull,
Ceri
i did some few changes on my code based on yours,
char a = 'a'; printf("output: %c \n", a); if (_ps3report->PressureCircle > 0 ) { a++;
but output only displays
Mac address is set to 00:02:72:AD:F3:5B , result = 8 output: a output: a output: a output: a output: a output: a output: a output: a output: a output: a
its not increasing or changing to B going Z, it just displays letter 'a'
posted by 15 Aug 2013The question is how you used it in your code. My guess is that it is a function called in response to USB input. So everytime a USB packet has arrived char a is set at 'a', and it is checked what kind of ps3report you got. If you want it to increment you need to define a globally if it is a C-style function, or if it is a class define it in your .h file as variable. In the constructor initiate it at 'a', and then you can happily increment it.
posted by 15 Aug 2013
I guess you figured out now that if should be while...
posted by Ad van der Weiden 14 Aug 2013