Don't have an account? Register now to chat, post, use our tools, and much more.
Latest Headlines
Online Users
There are 127 users online: 6 members, 90 guests and 31 bots. Members: ACagliano, fortytwo, legodude, Tari, Unomisan. Bots: VoilaBot (2), Spinn3r (1), MSN/Bing (1), Magpie Crawler (3), VoilaBot (5), Googlebot (18), MSN/Bing (1).
RSS & Social Media
SAX
You must log in to view the SAX chat widget
|
| Author |
Message |
|
gbl08ma
Power User

Joined: 26 Nov 2011 Posts: 475 Location: Portugal
|
Posted: 16 Aug 2012 06:23:53 am Post subject: Fixing my code |
|
|
This is yet another "request for help: fix my horrible code" thread... the problem is, I have spent a whole day already trying to fix some strange behavior and I don't seem to be able to.
I already asked for help on SAX yesterday and I can't seem to implement the suggestions people gave me, either :-/
Basically what the problematic part of my source code should do is take the information out of a calendar event struct and turn it into a string which can then be written to a file on the Storage Memory.
That string has some special characters, 0x1D and 0x1E, for separating fields and events, respectively.
http://pastebin.com/WEbTLNbS
I was warned on SAX that I shouldn't be using a 1-byte buffer for storing the string, like this char* buf = (char*)"";. I tried doing it with an array of a fixed size ( char buf[1000] ) and using sprintf again, but I can't get it to work.
Ultimately, I even managed to get \\fls0\\calendarevents.g3a written to the file instead of the output of sprintf!
I think this is because when I define a char buf[1000];, it points to parts of memory which are used already... it doesn't work if I try to char* buf = (char*)malloc(1000) either.
In conclusion, I'm getting really confused because I'm not able to use sprintf like I should (with a char array), and when I use a combination of itoa and concat instead of sprintf, 0x1D doesn't get written to the file (see comments on line 87 onwards) on a real Prizm (on the Manager Plus emulator, it does!). It just writes everything it should, but 0x1D is not there. My code is already a mix of unsigned char*, char*, and char[] with probably not-very-correct conversions between them
I already tried lots of ways to do what I want, but I just can't get it to work right from the end to the start.
All I want is to take unsigned int and char* out of a struct and write it to a file with some special characters separating each thing... how can this be so hard? _________________ My blog, where I write about random things... | tiny URL shortener
View JPEG images on your Prizm | Utilities for the Casio Prizm - clock, stopwatch, calendar/agenda, add-in manager and more! |
|
| Back to top |
|
|
hugh9860

Newbie

Joined: 08 Aug 2012 Posts: 32 Location: London, UK
|
Posted: 16 Aug 2012 08:45:22 am Post subject: |
|
|
it could be that sprintf doesn't work (anyone?)
i would recommend pursuing your itoa approach. does itoa work even? however, in your posted code `buf' and `smallbuf' don't point anywhere. you need to have them something like:
Code: char buf[1000];
char smallbuf[100];
or with numbers you can be sure you won't overrun. get rid of the `malloc' from concat otherwise this will chew up all your memory.
use this instead so that you always copy onto the end of `buf'
Code: char* strcat(char* dst, const char* src)
{
char* p = dst;
while (*p) ++p;
while ((*p = *src) != 0)
{
++p;
++src;
}
return dst;
}
otherwise you should be good.
hope this helps,
-- hugh. |
|
| Back to top |
|
|
gbl08ma
Power User

Joined: 26 Nov 2011 Posts: 475 Location: Portugal
|
|
| Back to top |
|
|
flyingfisch

Super-Expert

Joined: 02 Feb 2012 Posts: 895 Location: Akron, OH
|
Posted: 16 Aug 2012 08:52:39 am Post subject: |
|
|
| hugh9860 wrote: |
...
does itoa work even?
...
|
Yes, as far as I know, it does  _________________

 
 |
|
| Back to top |
|
|
gbl08ma
Power User

Joined: 26 Nov 2011 Posts: 475 Location: Portugal
|
|
| Back to top |
|
|
gbl08ma
Power User

Joined: 26 Nov 2011 Posts: 475 Location: Portugal
|
|
| Back to top |
|
|
|
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.
» Go to Registration page
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
© Copyright 2000-2013 Cemetech & Kerm Martian :: Page Execution Time: 0.028369 seconds.
|