This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

fprintf does not work in CCS simulator !!!



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?

  • 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.

  • Hey Guyz,

           Even i am facing a similar problem. Some one plz help me out.

    Problem: I have wirtten a small code which opens a file, reads the data into an array of size 50 and printing the read output on the console. The file from which i am reading the input contains just 4 four words. Even then i am not able to see any result when i run the code. I used the "expressions" window for looking into the stored value under the local variable. But it is showing an error "could read the value in the address 0x0 ..."  for each element of the 50 sized array. 

    Note: Printf works normally, i mean it prints out on the console if you ask for outputting any message. So i feel the main problem is with the file i/o operations.

    I am not understanding where exactly is the problem. I checked it by changing the heap and stack sizes to 1000 bytes. Even then no result.

    this is a sample file

    I am even uploading the files, i have worked on...

    #include <stdio.h>
    #include <msp430.h> 
    
    /*
     * hello.c
     */
    char q[50];
    int main(void) {
        WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
        printf("Enter the input:\n");
        FILE* in;
    
        in=fopen("test.txt","r");
        printf("hey\n");
        //fprintf(in,"%s","hellloooo");
        //rewind(in);
        //fclose(in);
    
        fscanf(in,"%s",q);
        //fread(q,50,1,in);
        //fgets(in,q);
    
        //printf("%s\n",q);
        fclose(in);
    	//puts("Hello World!\n");
    	//printf("hey");
    	return 0;
    }