how to generate text file for a program output?
-
Please read http://www.codeproject.com/Messages/2922875/HOW-TO-ASK-A-QUESTION.aspx[^]. You generate a text file by adding code to your program to collect the information to go in the file and writing it there. See http://msdn.microsoft.com/en-gb/library/windows/desktop/aa365747(v=vs.85).aspx[^] and http://msdn.microsoft.com/en-us/library/22z6066f(v=vs.100).aspx[^].
-
Please read http://www.codeproject.com/Messages/2922875/HOW-TO-ASK-A-QUESTION.aspx[^]. You generate a text file by adding code to your program to collect the information to go in the file and writing it there. See http://msdn.microsoft.com/en-gb/library/windows/desktop/aa365747(v=vs.85).aspx[^] and http://msdn.microsoft.com/en-us/library/22z6066f(v=vs.100).aspx[^].
Quote:
#include // for scandir #include // for alphasort and structure dirent #include // for MAXPATHLEN and getwd #include #include "Utility.c" #include "Utility.h" //#include #include #define FALSE 0 #define TRUE !FALSE extern int alphasort();// extern extend the visiblity of the function alphasort //alphasort used as the comparison function for the scandir() line no 24 function to sort the directory char pathname[MAXPATHLEN]; main() { int count,i; struct direct **files;//pointer to a pointer ,which point to the object call files here int file_select(); //printf("\n enter the file ") if (getwd(pathname) == NULL ) // return absolute file name of current directory { printf("Error getting path\n"); exit(0); } printf("Current Working Directory = %s\n",pathname); count = scandir(pathname, &files, file_select, alphasort);//scandir returns the current directory (.) and the directory above this (..) as well as all files so we need to check /* If no files found, make a non-selectable menu item */ if (count <= 0) { printf("No files in this directory\n"); exit(0); } printf("Number of files = %d\n",count); for (i=1;id_name); int SizeOfData,j; float *data; // float *text; char *wavFileName=".wav"; FILE *fout; /*if (argc < 2) { printf("\nUsage : SID_IITG waveFileName \n"); return -1; }*/ //wavRead(argv[1],&SizeOfData) ; data=wavRead(files[i-1]->d_name,&SizeOfData) ; //func call to read wave file // text =wavRead(files[i-1]->d_name,&SizeOfData) ; printf("\nReading Done\n"); fout = fopen ("dataSamples","w"); // output file // fout = fopen ("datasamples.txt","w"); j=0; while (j < SizeOfData) { //printf("%f\n",data[j]); fprintf(fout, "%f\n",data[j]); // fprintf(fout, "%f\n",text[j]); j++; } } printf("\n"); /* flush buffer */ } int file_select(struct direct *entry) { char *ptr; char *rindex(char *s, char c); if ((strcmp(entry->d_name, ".") == 0) || (strcmp(entry->d_name, "..") == 0)) return (FALSE); // checking of its extension ptr = rindex(entry->d_name, '.'); if ((ptr !=
-
Quote:
#include // for scandir #include // for alphasort and structure dirent #include // for MAXPATHLEN and getwd #include #include "Utility.c" #include "Utility.h" //#include #include #define FALSE 0 #define TRUE !FALSE extern int alphasort();// extern extend the visiblity of the function alphasort //alphasort used as the comparison function for the scandir() line no 24 function to sort the directory char pathname[MAXPATHLEN]; main() { int count,i; struct direct **files;//pointer to a pointer ,which point to the object call files here int file_select(); //printf("\n enter the file ") if (getwd(pathname) == NULL ) // return absolute file name of current directory { printf("Error getting path\n"); exit(0); } printf("Current Working Directory = %s\n",pathname); count = scandir(pathname, &files, file_select, alphasort);//scandir returns the current directory (.) and the directory above this (..) as well as all files so we need to check /* If no files found, make a non-selectable menu item */ if (count <= 0) { printf("No files in this directory\n"); exit(0); } printf("Number of files = %d\n",count); for (i=1;id_name); int SizeOfData,j; float *data; // float *text; char *wavFileName=".wav"; FILE *fout; /*if (argc < 2) { printf("\nUsage : SID_IITG waveFileName \n"); return -1; }*/ //wavRead(argv[1],&SizeOfData) ; data=wavRead(files[i-1]->d_name,&SizeOfData) ; //func call to read wave file // text =wavRead(files[i-1]->d_name,&SizeOfData) ; printf("\nReading Done\n"); fout = fopen ("dataSamples","w"); // output file // fout = fopen ("datasamples.txt","w"); j=0; while (j < SizeOfData) { //printf("%f\n",data[j]); fprintf(fout, "%f\n",data[j]); // fprintf(fout, "%f\n",text[j]); j++; } } printf("\n"); /* flush buffer */ } int file_select(struct direct *entry) { char *ptr; char *rindex(char *s, char c); if ((strcmp(entry->d_name, ".") == 0) || (strcmp(entry->d_name, "..") == 0)) return (FALSE); // checking of its extension ptr = rindex(entry->d_name, '.'); if ((ptr !=
-
Please read http://www.codeproject.com/Messages/2922875/HOW-TO-ASK-A-QUESTION.aspx[^]. You generate a text file by adding code to your program to collect the information to go in the file and writing it there. See http://msdn.microsoft.com/en-gb/library/windows/desktop/aa365747(v=vs.85).aspx[^] and http://msdn.microsoft.com/en-us/library/22z6066f(v=vs.100).aspx[^].
Quote:
#include // for scandir
#include // for alphasort and structure dirent
#include // for MAXPATHLEN and getwd
#include
#include "Utility.c"
#include "Utility.h"
//#include
#include
#define FALSE 0
#define TRUE !FALSEextern int alphasort();// extern extend the visiblity of the function alphasort
//alphasort used as the comparison function for the scandir() line no 24 function to sort the directorychar pathname[MAXPATHLEN];
main() { int count,i;
struct direct **files;//pointer to a pointer ,which point to the object call files here
int file_select();
//printf("\n enter the file ")
if (getwd(pathname) == NULL ) // return absolute file name of current directory
{ printf("Error getting path\n");
exit(0);
}
printf("Current Working Directory = %s\n",pathname);
count =
scandir(pathname, &files, file_select, alphasort);//scandir returns the current directory (.) and the directory above this (..) as well as all files so we need to check/\* If no files found, make a non-selectable menu item \*/ if (count <= 0) { printf("No files in this directory\\n"); exit(0); } printf("Number of files = %d\\n",count); for (i=1;id\_name); int SizeOfData,j;
float *data;
// float *text;
char *wavFileName=".wav";
FILE *fout;/*if (argc < 2) {
printf("\nUsage : SID_IITG waveFileName \n");
return -1;
}*///wavRead(argv[1],&SizeOfData) ;
data=wavRead(files[i-1]->d_name,&SizeOfData) ; //func call to read wave file
// text =wavRead(files[i-1]->d_name,&SizeOfData) ;
printf("\nReading Done\n");fout = fopen ("dataSamples","w"); // output file
// fout = fopen ("datasamples.txt","w");
j=0;
while (j < SizeOfData) {//printf("%f\\n",data\[j\]); fprintf(fout, "%f\\n",data\[j\]);
// fprintf(fout, "%f\n",text[j]);
j++;
}} printf("\\n"); /\* flush buffer \*/ }
int file_select(struct direct *entry)
{ char *ptr;
char *rindex(char *s, char c);
if ((strcmp(entry->d_name, ".") == 0) ||
(strcmp(entry->d_name, "..") == 0))
return (FALSE);
// checking of its extension
ptr = rindex(entry->d_name, '.');
if ((pt -
Quote:
#include // for scandir
#include // for alphasort and structure dirent
#include // for MAXPATHLEN and getwd
#include
#include "Utility.c"
#include "Utility.h"
//#include
#include
#define FALSE 0
#define TRUE !FALSEextern int alphasort();// extern extend the visiblity of the function alphasort
//alphasort used as the comparison function for the scandir() line no 24 function to sort the directorychar pathname[MAXPATHLEN];
main() { int count,i;
struct direct **files;//pointer to a pointer ,which point to the object call files here
int file_select();
//printf("\n enter the file ")
if (getwd(pathname) == NULL ) // return absolute file name of current directory
{ printf("Error getting path\n");
exit(0);
}
printf("Current Working Directory = %s\n",pathname);
count =
scandir(pathname, &files, file_select, alphasort);//scandir returns the current directory (.) and the directory above this (..) as well as all files so we need to check/\* If no files found, make a non-selectable menu item \*/ if (count <= 0) { printf("No files in this directory\\n"); exit(0); } printf("Number of files = %d\\n",count); for (i=1;id\_name); int SizeOfData,j;
float *data;
// float *text;
char *wavFileName=".wav";
FILE *fout;/*if (argc < 2) {
printf("\nUsage : SID_IITG waveFileName \n");
return -1;
}*///wavRead(argv[1],&SizeOfData) ;
data=wavRead(files[i-1]->d_name,&SizeOfData) ; //func call to read wave file
// text =wavRead(files[i-1]->d_name,&SizeOfData) ;
printf("\nReading Done\n");fout = fopen ("dataSamples","w"); // output file
// fout = fopen ("datasamples.txt","w");
j=0;
while (j < SizeOfData) {//printf("%f\\n",data\[j\]); fprintf(fout, "%f\\n",data\[j\]);
// fprintf(fout, "%f\n",text[j]);
j++;
}} printf("\\n"); /\* flush buffer \*/ }
int file_select(struct direct *entry)
{ char *ptr;
char *rindex(char *s, char c);
if ((strcmp(entry->d_name, ".") == 0) ||
(strcmp(entry->d_name, "..") == 0))
return (FALSE);
// checking of its extension
ptr = rindex(entry->d_name, '.');
if ((pt -
Your program could simply write its output to console (e.g. using
printf
function, orcout
object), then (on program invocation) you may redirect the standard output to a text file, e.g.myprogram > myfile.txt
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite
-
You should not use
fprintf
to write binary data (.wav files); useWriteFile
as I suggested in my previous post. You can usefprintf
to create a text file containing the names of all your files. -
Your program could simply write its output to console (e.g. using
printf
function, orcout
object), then (on program invocation) you may redirect the standard output to a text file, e.g.myprogram > myfile.txt
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite
-
Your program could simply write its output to console (e.g. using
printf
function, orcout
object), then (on program invocation) you may redirect the standard output to a text file, e.g.myprogram > myfile.txt
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite
-
There is the documentation for the very purpose of learning function (or object) usage: Basic Input/Output at C++ reference[^]. printf at C++ reference[^].
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite