Code:
#include<stdio.h>
#include<string.h>
int main(int argc, char *argv[])
{
int i,marker,k=0,pre=0,m,z;
char store[200],file[70],path[150],prev_path[150],modpath[150];
char add[150],refpath[150];
FILE *j,*fp;
j=fopen(argv[1],"r");//argv[1] specifies path of.csv file
fscanf(j,"%s",store);//store record in array store
for( i=0;i<200;i++)
if(store[i]==',') //find first ,
marker=i-1;
for(i=0;i<marker;i++)
{file[i]=store[i];}
file[i]='\0';
for(i=(marker+2);store[i]!='\0';i++) //initialise file and path from store
path[k++]=store[i];
path[k]='\0';
strcpy(prev_path,path); //initialise prev_path
strcpy(modpath,path); //intialise modpath
strcpy(add,argv[2]); //argv[2] specifies destination dir of reference files
for(z=0;z<150;z++)
{
if(modpath[z]==':')
modpath[z]='#';
else if (modpath[z]=='\\')
modpath[z]='#';
}
strcat(add,"\\");
strcat(add,modpath);
strcat(add,".txt");
strcpy(refpath,argv[3]);
strcat(refpath,"\\");//argv[3] contains path of installation base dir.
strcat(refpath,path);
fp=fopen(add,"a+");
fprintf(fp,"%s\n",refpath);
fprintf(fp,"%s\n",file);
while(!(feof(j))) //iterate for the remaining no. of records.
{
fscanf(j,"%s",store);
if(!(feof(j)))
{for( i=0;i<200;i++)
if(store[i]==',') //get position of ','
marker=i-1;
for(i=0;i<marker;i++)
{file[i]=store[i];}
file[i]='\0'; //intialise file and path from store
k=0;
for(i=(marker+2);store[i]!='\0';i++)
path[k++]=store[i];
path[k]='\0';
strcpy(modpath,path); //intialise modpath
if(!(strcmp(path,"\0")))
{ }
else if(!(strcmp(path,prev_path)))
{fprintf(fp,"%s\n",file);}
else if(strcmp(path,prev_path))
{
fclose(fp);
strcpy(add,argv[2]); //argv[2] specifies destination dir of reference files
for(z=0;z<150;z++)
{
if(modpath[z]==':')
modpath[z]='#';
else if (modpath[z]=='\\')
modpath[z]='#';
}
strcat(add,"\\");
strcat(add,modpath);
strcat(add,".txt");
strcpy(refpath,argv[3]);
strcat(refpath,"\\"); //argv[3] contains path of installation base dir.
strcat(refpath,path);
fp=fopen(add,"a+");
fprintf(fp,"%s\n",refpath);
fprintf(fp,"%s\n",file);
}
strcpy(prev_path,path);
}
}
}
Please help me, this is urgent.Thanks in advance