how do i make another main.c file where i can call this program and run according to it..?
-
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 !FALSEfloat 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
-
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 !FALSEfloat 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
-
You could just convert this code into a function which you can then add to a different project.
-
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.
-
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);
}
-
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);
}
-
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.
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
-
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
-
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 !FALSEfloat 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
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.
-
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.
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