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 do i make another main.c file where i can call this program and run according to it..?

how do i make another main.c file where i can call this program and run according to it..?

Scheduled Pinned Locked Moved C / C++ / MFC
questiontoolshelplounge
12 Posts 4 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.
  • L Lost User

    You could just convert this code into a function which you can then add to a different project.

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

    can u help me little deeper how to convert it .?

    L 1 Reply Last reply
    0
    • M mybm1

      can u help me little deeper how to convert it .?

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

      What's the problem? Just change the file name to something else, and change "main" to the name of your new function, with the appropriate parameters and return type.

      M 1 Reply Last reply
      0
      • L Lost User

        What's the problem? Just change the file name to something else, and change "main" to the name of your new function, with the appropriate parameters and return type.

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

        which procedure i have to run and do i need to create header file for the function?

        L 1 Reply Last reply
        0
        • M mybm1

          which procedure i have to run and do i need to create header file for the function?

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

          You don't run anything. Just create a new source file, define your function, by name, parameters and return type. You then use that from another file, either by defining it in the source, or by providing a header file with the definition. Something like ...

          // function.c

          include // your include statements here

          double myfunction(int count, double* numbers)
          {
          double result = 0.0;

          // your code here
          
          return result;
          

          }

          // main.c
          int main()
          {
          double myset[] = { 1.0, 2.3, 4.4 };

          extern double myfunction(int count, double\* numbers);
          double answer = myfunction(3, myset);
          

          }

          M 1 Reply Last reply
          0
          • L Lost User

            You don't run anything. Just create a new source file, define your function, by name, parameters and return type. You then use that from another file, either by defining it in the source, or by providing a header file with the definition. Something like ...

            // function.c

            include // your include statements here

            double myfunction(int count, double* numbers)
            {
            double result = 0.0;

            // your code here
            
            return result;
            

            }

            // main.c
            int main()
            {
            double myset[] = { 1.0, 2.3, 4.4 };

            extern double myfunction(int count, double\* numbers);
            double answer = myfunction(3, myset);
            

            }

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

            thanks as before Richard but in which way i have to run in terminal i m using ubuntu..

            L 1 Reply Last reply
            0
            • M mybm1

              thanks as before Richard but in which way i have to run in terminal i m using ubuntu..

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

              Use the editor (vi, emacs etc) to create your files and run your compiler or make processor to build them. If you really don't understand these basics of your system, then I suggest you get hold of, and study, a book or the Linux man pages.

              C 1 Reply Last reply
              0
              • L Lost User

                Use the editor (vi, emacs etc) to create your files and run your compiler or make processor to build them. If you really don't understand these basics of your system, then I suggest you get hold of, and study, a book or the Linux man pages.

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

                Man, you are patient. :thumbsup:

                THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite

                L 1 Reply Last reply
                0
                • C CPallini

                  Man, you are patient. :thumbsup:

                  THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite

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

                  Only very occasionally. I'm doing penance for my dumb question in the Database forum yesterday.

                  1 Reply Last reply
                  0
                  • M mybm1

                    Quote:

                    //===HEADER FILE ==============================================
                    #include"Utility.h" // IMPORT HEADER FILE
                    #include"Utility.c" // IMPORT C FILE
                    #include // for scandir
                    #include // for alphasort and structure dirent
                    #include

                    #include
                    #include
                    #include

                    #define FALSE 0
                    #define TRUE !FALSE

                    float square(float b); // FUNCTION FOR SQUARING NUMBER ...
                    //float summation(float g);
                    char pathname[MAXPATHLEN];

                    int main(int argc,int *argv[])
                    {
                    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);
                      		        //printf("\\n \\nFile with extension .wav are as follows\\n ");
                    

                    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("\\n Number of files = %d\\n",count);
                      	for (i=1;id\_name);
                    
                    
                      				srand(12345); // generate same random number anytime it run
                      					       //srand((unsigned int)time NULL)
                      				int i,j;
                      				float y,sum=0.0;
                      				float a=0.2;
                      				float summation=0.0;
                      				int SizeOfData;
                      				float \*data;
                    

                    data=wavRead(files[i-1]->d_name,&SizeOfData) ;

                    //================== OUTPUT DISPLAY SCREEN======================================================================

                        printf("\\n\\n========================================================\\n");
                    

                    printf("Generated random number\t || Squaring of random number:\n");
                    printf("=========================================================\n");

                    for(i=0;i

                    S Offline
                    S Offline
                    Software_Developer
                    wrote on last edited by
                    #11

                    In C++, you can only have one main. The standard explicitly says in 3.6.1: A program shall contain a global function called main, hich is the designated start of the program. [...] This function shall not be overloaded. You can have two functions called main. The name is not special in any way and it's not reserved. What's special is the function, and it happens to have that name. The function is global. So if you write a main function in some other namespace, you will have a second main function.

                    namespace secondMain
                    {
                    int main() { return 0; }
                    }

                    int main()
                    {
                    secondMain::main();

                    }

                    The first main function is not special - notice how you have to return explicitly.

                    C 1 Reply Last reply
                    0
                    • S Software_Developer

                      In C++, you can only have one main. The standard explicitly says in 3.6.1: A program shall contain a global function called main, hich is the designated start of the program. [...] This function shall not be overloaded. You can have two functions called main. The name is not special in any way and it's not reserved. What's special is the function, and it happens to have that name. The function is global. So if you write a main function in some other namespace, you will have a second main function.

                      namespace secondMain
                      {
                      int main() { return 0; }
                      }

                      int main()
                      {
                      secondMain::main();

                      }

                      The first main function is not special - notice how you have to return explicitly.

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

                      However, the OP code is C, you know, another programming language. ;)

                      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