sorry, i thought this would be a common problem,
anyway here is the code.
And please tell me, if possible, if i can improve the code with any other special library functions!
Thanks
Code:
/*Sequentially read the whole audio book*/
#include "stdio.h"
#include "string.h"
long global_offset;
int count = 0;
main()
{
char *lookinfile, *searchfile, *foundfile;
int headercount, i;
char *lookforfile(char * , char * , int);
clrscr();
for(i=0; i<5; i++)
{
lookinfile = "0ncc.txt";
searchfile = "smil";
headercount = 1;
foundfile = lookforfile(lookinfile, searchfile, headercount);
printf("\n%s",foundfile);
searchfile = "mp3";
foundfile = lookforfile(foundfile, searchfile, headercount);
printf("\n%s",foundfile);
}
}
char *lookforfile(char *lookinfile, char *searchfile, int headercount)
{
char ch;
int j;
long offset;
FILE *fp;
char *lookupfile, *global_next_header, *returnfile;
fp = fopen(lookinfile,"r");
lookupfile = "smil";
if(searchfile[0]==lookupfile[0])
{
if(count == 0)
{
while(count != headercount)
{
/*LOOK FOR headerstring;*/
ch=fgetc(fp);
if(ch=='<')
{
if((ch=fgetc(fp))=='h')
{
if((ch=fgetc(fp))=='1')
{
/*FOUND H1?*/
count = count+1;
}
}
}
}
}
if(count>1)
{
fseek(fp, global_offset, SEEK_SET);
}
while(ch!='\n')
{
/*Look for h ref="......"*/
/*... *lookupfile = "xyz.smil" */
if((ch=fgetc(fp))=='h')
{
if((ch=fgetc(fp))=='r')
{
if((ch=fgetc(fp))=='e')
{
if((ch=fgetc(fp))=='f')
{
if((ch=fgetc(fp))=='\=')
{
if((ch=fgetc(fp))=='\"')
{
j=0;
while((ch=fgetc(fp))!='\#')
{
returnfile[j]=ch;
j++;
}
returnfile[j]='\0';
}
}
}
}
}
}
}
/*WHAT IS NEXT AVAILABLE HEADER?*/
while((ch=getc(fp))!='\<');
j=0;
while((ch=getc(fp))!='\ ')
{
global_next_header[j]=ch;
j++;
}
count = count+1;
global_offset = ftell(fp);
global_next_header[j]='\0';
return(returnfile);
}
lookupfile="mp3";
/*LOOK UP MP3 FILE */
if(searchfile[0]==lookupfile[0])
{
/*Look for audio src"......"*/
/*...*lookupfile = "abc.mp3"...*/
while((ch=fgetc(fp))!='\n')
{
if(ch=='s')
{
if((ch=fgetc(fp))=='r')
{
if((ch=fgetc(fp))=='c')
{
if((ch=fgetc(fp))=='\=')
{
if((ch=fgetc(fp))=='\"')
{
j=0;
while((ch=fgetc(fp))!='\"')
{
returnfile[j]=ch;
j++;
}
returnfile[j]='\0';
}
}
}
}
}
}
return(returnfile);
}
}