NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Parsing a string in a function
February 17, 2011 by MichaelJE2 ![]() |
Ok, so this code compiles, but doesn't run properly. When I call the function strToBlink("michael"); (which I wrote in a separate .c file, and did all the necessary things to make work) it simply skips over that bit of code. Here is the function (I've tested the functions it calls as well, they work just fine).
|
---|---|
February 19, 2011 by hevans (NerdKits Staff) ![]() |
Hi MichaelJE2, I see no reason why your code would just skip over the function here. My suggestion is to print out some debug statements. Maybe check out what the value of l is, perhaps strlen is doing something weird. Humberto |
February 19, 2011 by bretm ![]() |
When you say strToBlink("Michael") it won't work with the default way that Nerdkits makefiles are configured. Sram-based strings don't get initialized. Even if you fix the makefile you would be wasting valuable Sram space on a constant string value which would have to start out in program memory anyway. Use the PSTR macro around the string and pgm_read_byte to read the characters from the char* locations. Check for a zero byte to end the string instead of using strlen, otherwise you end up making two passes over the sring. |
February 19, 2011 by MichaelJE2 ![]() |
Ah hah! I will try your suggestion when I get the ATmega328 upgrade (I hooked up my 168 to power wrong, and fried it) But I'll bet that'll fix it. |
February 26, 2011 by BobaMosfet ![]() |
Why are you incrementing 'i' BEFORE you make your call to charToBlink()? --- '++i' tells it to increment 'i' and then execute the statement in the loop. I would think you would want to increment it afterwards like this: 'i++' Without seeing charToBlink(), we're not seeing the entire algorithm. BM |
February 27, 2011 by MichaelJE2 ![]() |
I tried hevans' suggestion, and it worked. Thanks! :) |
Please log in to post a reply.
Did you know that you can connect to certain car computers via the OBD-II port with a microcontroller? Learn more...
|