Hi, all,
I have a question: anyone knows a way to make fprintf work in CCS simulator?
I wrote a short C program to read 3 lines of integer data (in input.txt) into an array of size 3, and then write them from the array to a file (output.txt). I use fscanf to read and fprintf to write respectively. I ran the program successfully in the unix environment and confirmed that the 3 data have been written to the output.txt file correctly.
However, when I ran the same program in CCS simulator, I confirmed that the 3 data have been read to the array defined in the program successfully, but the data were not written from the array to output.txt successfully. The size of output.txt is always 0, after running the program. In other words, fscanf works but fprintf does not work in CCS simulator.
Anyone can guide me what's wrong with the use of fprintf in CCS simulator? Did I miss anything?
Many thanks.
Hi Xuedong,I do not know of any bugs that prevent fprintf from functioning in the Simulator, but there are some common places to check for errors. First off I suggest that you ensure that you have a sufficient stack and heap size. Many of the RTS functions require the use of both (especially printf) so you may want to try beefing the sizes of both up a bit to see if it helps. Additionally which Simulator are you working with and in which version of CCS?
-Tim
---------------------------------------------------------------------------------------------------------Please click the Verify Answer button on this post if it answers your question.---------------------------------------------------------------------------------------------------------
Thanks, Tim.
I am using CCS 3.3 and C6416 Device Cycle Accurate Simulator.
Strangely, I can see the output data in CCS stdout window when using printf, while the output file size is 0 when using fprintf. If this is the issue of stack and/or heap size, I guess that both printf and fprintf will not work.
Anyway, I will check stack/heap size as you suggested. Thanks.
Hi, Tim,
Now it is working.
After adding fclose(), I saw the output data in the output file, as expected. Seems to me that fclose is needed in CCS, while in the unix environment, it is not needed.
Anyway, it solves the problem. Thank you for your advice.
Good to know. I am glad to hear you got it working.