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?
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?