Hi all,

I am very new to C code and was wondering if someone could please help me.

i am using a program that gets run through a windows command prompt and outputs the result to the command line screen by default. i was trying to get it to output the results to a .csv file injstead but i have no idea how to do this. this is how it outputs it to the command line:

printf( "%d%s%s%s%d%s%s%s%d\n", index, delim, deltime, delim, type, delim, filename, delim, filesize );

can some one please help me?

thanks in advance

scoobie,

from the command prompt just redirect the output to a file

c:> myprog.exe >file.csv <Enter>

i am using a program that gets run through a windows command prompt and outputs the result to the command line screen by default. i was trying to get it to output the results to a .csv file injstead but i have no idea how to do this.

You have to change the program to make the output come out in CSV format. Ancient Dragon's advice will get the data into a file for you, but it won't be in CSV format. It'll still look like the screen.

> printf( "%d%s%s%s%d%s%s%s%d\n", index, delim, deltime, delim, type, delim, filename, delim, filesize );

Something like

FILE *fp = fopen( "file.csv", "w" );
fprintf( fp, "%d%s%s%s%d%s%s%s%d\n", index, delim, deltime, delim, 
         type, delim, filename, delim, filesize );
fclose( fp );

csv format uses commas between fields, and I believe that text fields which contain commas should be enclosed in quotes.

FILE *fp = fopen( "file.csv", "w" );
fprintf( fp, "%d,\"%s\",\"%s\",\"%s\",%d,\"%s\",\"%s\",\"%s\",%d\n", index, delim, deltime, delim, 
         type, delim, filename, delim, filesize );
fclose( fp );
commented: Good - [Grunt] +1

> and I believe that text fields which contain commas should be enclosed in quotes.
Yeah, I wasn't going there - too tricky ;)
If the strings contain quotes as well as commas, its going to get ugly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.