Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to generate text file for a program output?

how to generate text file for a program output?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
12 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M mybm1

    how to generate text file for a program output?

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #2

    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[^].

    M 2 Replies Last reply
    0
    • L Lost User

      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[^].

      M Offline
      M Offline
      mybm1
      wrote on last edited by
      #3

      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 !=

      L 1 Reply Last reply
      0
      • L Lost User

        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[^].

        M Offline
        M Offline
        mybm1
        wrote on last edited by
        #4

        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 ((pt

        L 1 Reply Last reply
        0
        • M mybm1

          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 !=

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #5

          And? Do you have a question?

          1 Reply Last reply
          0
          • M mybm1

            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 ((pt

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #6

            You should not use fprintf to write binary data (.wav files); use WriteFile as I suggested in my previous post. You can use fprintf to create a text file containing the names of all your files.

            M 1 Reply Last reply
            0
            • M mybm1

              how to generate text file for a program output?

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #7

              Your program could simply write its output to console (e.g. using printf function, or cout 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

              M 2 Replies Last reply
              0
              • L Lost User

                You should not use fprintf to write binary data (.wav files); use WriteFile as I suggested in my previous post. You can use fprintf to create a text file containing the names of all your files.

                M Offline
                M Offline
                mybm1
                wrote on last edited by
                #8

                do this WriteFile function work in ubuntu ?

                L 1 Reply Last reply
                0
                • C CPallini

                  Your program could simply write its output to console (e.g. using printf function, or cout 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

                  M Offline
                  M Offline
                  mybm1
                  wrote on last edited by
                  #9

                  Actually without giving command I want to generate itself..that why but Thanks anyhow..

                  1 Reply Last reply
                  0
                  • M mybm1

                    do this WriteFile function work in ubuntu ?

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #10

                    My apologies, you need fwrite[^] in Linux.

                    1 Reply Last reply
                    0
                    • C CPallini

                      Your program could simply write its output to console (e.g. using printf function, or cout 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

                      M Offline
                      M Offline
                      mybm1
                      wrote on last edited by
                      #11

                      By the way how to use this function?

                      C 1 Reply Last reply
                      0
                      • M mybm1

                        By the way how to use this function?

                        C Offline
                        C Offline
                        CPallini
                        wrote on last edited by
                        #12

                        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

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups