How to speed up c code? : <p>I am wondering if there is any way to speed up this simple .c program I made alongside a friend. Is there any things I could change to clean it up as well? And maybe add a pop up to say how many images it has processed. Thanks!</p>

<pre><code>#include "stdio.h"
#include "string.h"
#include "malloc.h"
#define DDS_MAGIC "DDS "
int ipos[10240];
int iposind=0;
int tfilelen;
char* TransBuf=NULL;
int main(int argc, char** argv){
    int i,r;
    FILE* sFile=NULL;
    FILE* tFile=NULL;
    char ifn[256];
    char ofn[256];
    char qc;
    if (argc !=2){
        printf("usage: %s filename\n",argv[0]);
        return 0;
    }
    strcpy(ifn,argv[1]);
    sFile=fopen(argv[1],"rb");
    fseek(sFile,0,SEEK_END);
    tfilelen=ftell(sFile);
    fseek(sFile,0,SEEK_SET);
    TransBuf=(char*)malloc(tfilelen);
    for(i=0,r=0;r&lt;tfilelen;){
    /* read the file in */
    i=fread(TransBuf+r,1,tfilelen-r,sFile);
    if(i&gt;0)r+=i;
    }
    qc=DDS_MAGIC[0];
    for(i=0;i&lt;tfilelen;i++){
        if(TransBuf[i]!=qc)continue;
        if(strncmp(DDS_MAGIC,TransBuf+i,4)==0){
            ipos[iposind]=i;
            iposind++;
        }
    }
    ipos[iposind]=tfilelen;
    for(i=0;i&lt;iposind;i++){
        char* s;
        int l;
        int j;
        s=TransBuf+ipos[i];
        l=ipos[i+1]-ipos[i];
        if(l&lt;4)continue; /* don't write out dds files with no data*/
        /* write each dds segment to it's own file */
        sprintf(ofn,"%s_%d.dds",ifn,i);
        tFile=fopen(ofn,"w+b");
        for(j=0,r=0;r&lt;l;){
            j=fwrite(s+j,1,l-r,tFile);
            if(j&gt;0)r+=j;
        }
        fclose(tFile);
         system("pause");
    }
    printf("extracted %d files\n",i);
    return 0;
}
</code></pre>
