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.

file commands usage....

I am using Omap L137 EVM and CCSv3.3. While writing a program on DSP, I used file commands like fopen, fprintf,... but they were not supported( the fopen gave a null pointer). Aren't these commands supported??? Can't we take input from files and write output to files ???

  • Yes, they are supported and they work.

    Please make sure that you have a good heap size. Also make sure that you are putting the correct path to the file.

    Please see:

    http://community.ti.com/forums/p/4357/16217.aspx#16217

     

  •  

    From the link given here, I understood that heap memory should be enabled and heap size should be given. After doing it, stdout tab appeared, malloc() function is working but not the file commands.

    For my application, I need to read a lot of float data from a file and write float data to files

  • FYI I am providing the code and the errors

    "FILE *fp=fopen("input","r");"

    Watch window:

    fp    0x00000000    FILE *    hex    Edited
    fd    memory map prevented read of target memory at 0x00000000        dec    NotEdited
    buf    memory map prevented read of target memory at 0x00000004        dec    NotEdited
    pos    memory map prevented read of target memory at 0x00000008        dec    NotEdited
    bufend    memory map prevented read of target memory at 0x0000000C        dec    NotEdited
    buff_stop    memory map prevented read of target memory at 0x00000010        dec    NotEdited
    flags    memory map prevented read of target memory at 0x00000014        dec    NotEdited

     

  • Try increasing the size of the heap.

    Also, are you including stdio.h?

    #include <stdio.h>

  • tried increasing the heap size but in vain...

    as of now, using break point mechanism to read/write data...but should know how to solve the problem of file commands..pls help...

  • If you want to attach a simple test case I can take a look for you.

  • thanks in advance for looking into the problem....i attached the sample project to my profile....pls have a look at it...

    here is the link: http://e2e.ti.com/members/1373604/default.aspx

  • John,

    I was able to open the file with your project. I just replaced:

    //FILE *fp=fopen("prgm-o/p.txt","w");

    With:
    FILE *fp=fopen("input.txt","w");

    as there is no prgm-o/p.txt file. Please see figure:

  • what I understand is that the files to be read have to be stored in Debug folder..yeah its reading from the files..

    but the problem is still there...file is opened for writing... but it is not writing to the files...pls check once...

  • Hi John,

    Yes, the files are expected to be in the same folder as your executable (.out), it the file is not in the same folder you need to provide a path to it. I was able to write to input.txt that is in the Debug folder using the following code:

    #include<stdio.h>
    #include<stdlib.h>

    int main()
    {
    int a=3;
    char str[70]= "Hello world Hello world Hello world Hello world Hello world ";
    FILE *fp=fopen("input.txt","w");
    a=fputs(&str[0], fp);
    fclose(fp);
    return 0;
    }

  • thanks a lot for your help...file commands are working properly...

    i observed a strange behavior here.... when i dont write the fclose() in the code, the string o/p is not written to the output file....but if i include the statement, o/p is properly written...

    moreover, this doesn't apply to float data...i intentionally removed the fclose() when writing float data and it was working properly...surprising!!!!!

    Thanks Mariana.....

  • I have got another problem..... while using file commands...

    i use a write function which does writing data to a file and a read function which reads data from a file(using fopen, fprintf, fscanf,...). In debug mode, when i step over the statement " FILE *file = fopen(output,"a");" where output is char array which has the name of the file to be opened, the yellow arrow mark (the one which appears in debug mode) disappears(but still indicating 'stepping over')

    i have read that there is a limit on the no. of streams that can be opened...i dont use printf,scanf (thus not using std in out streams..i hope) but i use LOG_message and took every care to reduce the streams used but in vain....what is the problem here & what might be the solution????

  • John, not sure if I understand, could you please explain a little better or send another test case. What size if heap did you put? You could try increasing the size ...