|
|
<blockquote class="quote"><div class="op">Quote:</div>
#include"Utility.h"
#include"Utility.c"
#include <sys/types.h>
#include <sys/dir.h>
#include <sys/param.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define FALSE 0
#define TRUE !FALSE
float square(float b);
char pathname[MAXPATHLEN];
int main(int argc,int *argv[])
{
int count,i;
struct direct **files;
int file_select();
if (getwd(pathname) == NULL )
{
printf("Error getting path\n");
exit(0);
}
count = scandir(pathname, &files, file_select, alphasort);
if (count <= 0)
{
printf("No files in this directory\n");
exit(0);
}
printf("\n Number of files = %d\n",count);
for (i=1;i<count+1;++i)
{
printf("\n%s\n ",files[i-1]->d_name);
srand(12345);
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) ;
printf("\n\n========================================================\n");
printf("Generated random number\t || Squaring of random number:\n");
printf("=========================================================\n");
for(i=0;i<SizeOfData;i++)
{
float f= ((float)rand()/(float)(RAND_MAX))*a;
printf("%f\t",f);
y=square(f);
printf("\t\t%f\n",y);
sum +=y;
}
printf("\n===================================================\n");
printf("\n TOTAL SUM OF THE SQUARED NUMBER := %f\t\n",sum);
summation=sum/SizeOfData;
printf("\n ENERGY OF NOISE SIGNAL := \t%f/%d=%f\n\n",sum,SizeOfData,summation);
FILE *fout;
fout=fopen("NOISE SIGNAL","w");
j=0;
sum=0.0;
srand(12345);
fprintf(fout,"\n================================================================\n");
fprintf(fout,"\nGENERATED RANDOM NUMBER || SQUARING OF GENERATED RANDOM NUMBER\n");
fprintf(fout,"\n=================================================================\n");
while(j<SizeOfData)
{
float f= ((float)rand()/(float)(RAND_MAX))*a;
y=square(f);
fprintf(fout,"\t%f\t\t\t%f\n",f,y);
sum +=y;
j++;
}
fprintf(fout,"\n===============================================\n");
fprintf(fout,"\nTOTAL SUM OF THE SQUARED NUMBER:=\t%f",sum);
summation=sum/SizeOfData;
fprintf(fout,"\nENERGY OF NOISE SIGNAL e(n):=\t%f/%d = %f\n\n",sum,SizeOfData,summation);
fclose(fout);
}
float square(float b)
{
float z;
z=b*b;
return(z);
}
</blockquote>
|
|
|
|
|
You could just convert this code into a function which you can then add to a different project.
|
|
|
|
|
can u help me little deeper how to convert it .?
|
|
|
|
|
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.
|
|
|
|
|
which procedure i have to run and do i need to create header file for the function?
|
|
|
|
|
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 ...
# include double myfunction(int count, double* numbers)
{
double result = 0.0;
return result;
}
int main()
{
double myset[] = { 1.0, 2.3, 4.4 };
extern double myfunction(int count, double* numbers);
double answer = myfunction(3, myset);
}
|
|
|
|
|
thanks as before Richard but in which way i have to run in terminal i m using ubuntu..
|
|
|
|
|
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.
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
|
|
|
|
|
Only very occasionally. I'm doing penance for my dumb question in the Database forum yesterday.
|
|
|
|
|
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
|
|
|
|
|
Hello guys,
I have a problem. I'm writing to a log file, but when I do the application throws:
An unhandled exception of type 'System.AccessViolationException' occurred in ****
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
The code (unmanaged) I'm using is this one:
inline bool writeLog(nsCLog::eSeverity severity, string message)
{
ofstream myfile;
if( ((int)severity) >= mLogLevel)
{
myfile.open(mStrSource.c_str(), ios::in | ios::out | ios::app);
if(!myfile.is_open())
{
throw "Unable to open the file: " + mStrSource;
}
myfile << "TESTE" << endl;
myfile.close();
}
}
return true;
};
When receiving this error, the code points to the _Lock() of file fstream:
virtual void __CLR_OR_THIS_CALL _Lock()
{ if (_Myfile)
_CSTD _lock_file(_Myfile);
}
Other info:
Developed under VS2010 (Incially the project was Winx32 but now it's Winx64) (.NET Framework 4).
The open() method of ofstream creates the file and the file is writable but throws the exception when try's to write on the file.
Thank you guys in advanced.
modified 1-Aug-14 12:23pm.
|
|
|
|
|
Just for curiosity: why are you throwing a string and catching a bad_alloc ?
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
|
|
|
|
|
Hello,
It's a typo
I'm going to remove it.
Thanks
|
|
|
|
|
You are welcome.
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
|
|
|
|
|
Ok guys,
For future notice, the problem was related to the configuration of the project. When I converted the project from .net 3.5 to .net 4 and from x32 to x64 something didn't quite go right.
So I reverted everything back and converted again in a more controlled environment and now i can open/write/close files without a problem.
Cya
|
|
|
|
|
Hello,
How you fixed the access violation error on Visual Studio 2010. I am trying to write data to csv file but it is giving me access violation error. As you mentioned, the debugger points to :
virtual void __CLR_OR_THIS_CALL _Lock()
{ // lock file instead of stream buffer
if (_Myfile)
_CSTD _lock_file(_Myfile);
}
|
|
|
|
|
I have a VC++/MFC application.This was in ancient code, visual studio 6. While compiling it in VS2010 it gave tons of errors and required changes in settings. I got good guidance from http://www.codeproject.com/Members/Jochen-Arndt.
Now my project is compiling/linking and .exe file is also launching.
While the application is running since output is in Japanese so in English OS it shows all junk characters.
Now i take the whole code base to Japanese windows OS, compile the code and run the application there,
Why do I still see the junk characters on application dialogue boxes/captions/ Labels ?
Any area you can hint I can look into display caption/labels/dialogue box in Japanese ?
Please help.
|
|
|
|
|
The obvious question: have you selected Japanese font into the application's resources?
|
|
|
|
|
Obvious answer...that's why its showing Junk characters in the english OS.
modified 31-Jul-14 6:04am.
|
|
|
|
|
Can someone point me to some C++ or C# examples on how to loop thru a group of similar CSV files and import them to an access db? Thanks.
|
|
|
|
|
|
Hi,
I am working on a project which requires to use a web service in C++ native application. I have searched on the net and found many links which explains that it is possible using C++ REST SDK. I have downloaded and installed the C++ REST SDK for visual studio 2010 but couldn't find any sample application using REST SDK to call a web service.
Can anyone help me regarding this. How to use a web service in C++ using REST SDK.
Regards,
mba
|
|
|
|