hello all,
following is the code that fetches required columns from r.csv and makes a new file.
now i want to ignore first line of r.csv while fetching defined column .
what should be done?
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *in, *out;
char ch;
char *rdf,*wdf;
int comma_count = 0;
int wait_for_newline = 0;
clrscr();
rdf="A:\\r.csv";
wdf="A:\\abl.csv";
in = fopen(rdf,"r");
out = fopen(wdf,"w");
if(in == NULL)
{
printf("Cannot open input file.\n");
exit(1);
}
if(out == NULL)
{
printf("Cannot open output file.\n");
exit(1);
}
while(!feof(in))
{
ch = getc(in);
if(ferror(in))
{
printf("Read Error");
clearerr(in);
break;
}
else
{
if(!feof(in))
{
if(ch=='\n')
{
wait_for_newline = 0;
comma_count = 0;
}
if(ch==',')
{
comma_count++;
}
if((comma_count == 8 && wait_for_newline==0))
{
if(ch==',')
putc('\n', out);
else
putc(ch, out);
}
if(comma_count == 9 && wait_for_newline == 0)
{
if(ch==',')
putc(' ', out);
else
putc(ch, out);
}
if(comma_count == 10 && wait_for_newline == 0)
{
if(ch==',')
putc(' ', out);
else
putc(ch, out);
}
if(comma_count == 11 && wait_for_newline == 0)
{
if(ch==',')
putc(' ', out);
else
putc(ch, out);
}
if(comma_count == 12 && wait_for_newline == 0)
{
if(ch==',')
putc(' ', out);
else
putc(ch, out);
}
if(comma_count == 13 && wait_for_newline == 0)
{
if(ch==',')
putc(' ', out);
else
putc(ch, out);
}
if(comma_count == 26 && wait_for_newline == 0)
{
if(ch==',')
putc(' ', out);
else
putc(ch, out);
}
if(comma_count == 27 && wait_for_newline == 0)
{
if(ch==',')
putc(' ', out);
else
putc(ch, out);
}
if(comma_count == 28 && wait_for_newline == 0)
{
if(ch==',')
putc(' ', out);
else
putc(ch, out);
}
if(comma_count == 29 && wait_for_newline == 0)
{
if(ch==',')
putc(' ', out);
else
putc(ch, out);
}
if(comma_count == 30 && wait_for_newline == 0)
{
if(ch==',')
putc(' ', out);
else
putc(ch, out);
}
}
if(ferror(out))
{
printf("Write Error");
clearerr(out);
break;
}
}
}
printf("\n File has been successfully created.");
fclose(in);
fclose(out);
getch();
getch();
return 0;
}