|
Perhaps your request could have been worded better; the word 'hack' tends to ring alarm bells.
|
|
|
|
|
haha my bad. anw i managed to do it. basically do buffer overrun and when the system crash, find the return address. use ASCII to input the function address that u wanna gain access to.
|
|
|
|
|
Hey I would like to appreciate your intension behind the question. I would strongly suggest this[^]
|
|
|
|
|
Can someone please look at this and tell me what I am doing wrong with my pointer.
#include <stdio>
#include <stdlib.h>
#define SENT 4 //"Quit" menu choice
void DisplayMenu (void);
int GetMenuChoice (void);
void Gen2Rand (int*r1, int*r2);
void DrillOneProb (int c, int r1, int r2);
int main (void)
{
int c;
int r1,
r2;
DisplayMenu();
c = GetMenuChoice();
while (c >= 1 && c < SENT)
{ Gen2Rand (&r1, &r2);
DrillOneProb (c, r1,r2);
DisplayMenu();
c = GetMenuChoice();
printf("Program Complete\n");}
return (0);
}
void DisplayMenu (void)
{
printf("MENU OF OPERATIONS\n");
printf("1. Addition.\n");
printf("2. Subtraction.\n");
printf("3. Multiplication.\n");
printf("4. Quit.\n\n");
}
int GetMenuChoice (void)
{
int c;
do{
printf ("Enter the number of the operation to try (1-4):\n");
scanf ("%d", &c);
if (c<1 || c>SENT)
printf("\aInput value is out of range.\n");
while (c < 1 || c > SENT);
return (c);
}
void Gen2Rand (int*r1p, int*r2p)
int r1;
int r2;
r1 = 2 + rand() % 11;
r2 = 2 + rand() % 11;
*r1p = r1;
*r2p = r2;
return (0);
}
void DrillOneProb (int c, int r1, int r2)
{
int CorAns,
Reply;
switch (c)
{
case 1:
printf("+");
CorAns = r1 + r2;
break;
case 2:
printf("-");
CorAns = r1 - r2;
break;
default:
printf("x");
CorAns = r1 * r2;
break;
}
printf(" %d, ?", Reply);
scanf ("%d", &Reply);
if
(Reply == CorAns)
printf("Yes, that is correct. Good Job!");
else
{ printf("No, the correct answer is: %d", CorAns);
printf("\n\n");
}
|
|
|
|
|
You've not stated what problems if any that you're having?
PS:
In your function prototypes, you don't need to specify any variable names for the parameters. Just the data types are OK. This is Ok:
void DrillOneProb (int, int, int);
|
|
|
|
|
void Gen2Rand (int*r1p, int*r2p)
1. Error is undeclared identifier r2p
2. type error in argument 2 to 'Gen2Rand', found 'int' expected 'pointer to int'
3. possible usage of r1p and r2p before definition
*r1p = r1;<br />
*r2p = r2;
1. Error is r1p and r2p is not a pointer.
I met my instructor yesterday and he said that the prototypes were correct. So should I change the void Gen2Rand (int*r1, int*r2)
|
|
|
|
|
Ibrahim Bello wrote: In your function prototypes, you don't need to specify any variable names for the parameters. Just the data types are OK. This is Ok:
void DrillOneProb (int, int, int);
But not very helpful to someone looking at a function prototype in a header file.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
You are missing: 1) a closing brace in GetMenuChoice() , and 2) an opening brace in Gen2Rand() . There are other errors but addressing those two should get you further along.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Thank you, That did fix the prob.
|
|
|
|
|
That's good.
As for the prototype, this is OK:
void Gen2Rand (int*, int*); . No need for specifying variable names in prototype. Just let the compiler know what data type to expect for that function. Cheers!
|
|
|
|
|
IMHO, I would say that it is good practice to specify the parameter names in the function prototype, especially when the parameters are the same type. This is not for the compiler's sake but for your own sanity when you come to call the function. It will help you to get your parameters in the right order without having to analyze your code.
Tony 
|
|
|
|
|
Oh yes, that's right,
Guess I'm just used to leaving my parameter names out 
|
|
|
|
|
 I figured it would. You might consider formatting your code (e.g., using spaces instead of tabs) so that errors such as mismatched braces would be more obvious. For example:
#define SENT 4 //"Quit" menu choice
void DisplayMenu (void)
{
printf("MENU OF OPERATIONS\n");
printf("1. Addition.\n");
printf("2. Subtraction.\n");
printf("3. Multiplication.\n");
printf("4. Quit.\n\n");
}
int GetMenuChoice (void)
{
int c;
do
{
printf ("Enter the number of the operation to try (1-4):\n");
scanf ("%d", &c);
if (c<1 || c>SENT)
printf("\aInput value is out of range.\n");
} while (c < 1 || c > SENT);
return (c);
}
void Gen2Rand (int*r1p, int*r2p)
{
int r1;
int r2;
r1 = 2 + rand() % 11;
r2 = 2 + rand() % 11;
*r1p = r1;
*r2p = r2;
}
void DrillOneProb (int c, int r1, int r2)
{
int CorAns,
Reply;
switch (c)
{
case 1:
printf("+");
CorAns = r1 + r2;
break;
case 2:
printf("-");
CorAns = r1 - r2;
break;
default:
printf("x");
CorAns = r1 * r2;
break;
}
printf(" %d, ?", Reply);
scanf ("%d", &Reply);
if (Reply == CorAns)
printf("Yes, that is correct. Good Job!");
else
{
printf("No, the correct answer is: %d", CorAns);
printf("\n\n");
}
}
int main (void)
{
int c;
int r1,
r2;
DisplayMenu();
c = GetMenuChoice();
while (c >= 1 && c < SENT)
{
Gen2Rand (&r1, &r2);
DrillOneProb (c, r1,r2);
DisplayMenu();
c = GetMenuChoice();
printf("Program Complete\n");
}
return (0);
}
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Thanks again. I will make a notation in regards to the braces. I did make some other changes because the execute did not look like the sample given. But now works perfectly.
|
|
|
|
|
OK, actually this program works fine, but only when run from Visual Studio. However, when I click on the .exe or launch it from windows command prompt, I get an error: "Unhandled exception at 0x775e59c3 in Materials.exe: 0xC0000005: Access violation reading location 0x54a075d8" and Windows shuts the program down.
The Requirement
The program is to read from a text file a list of tabulated data of a given material: Temperature, Density, Viscosity... etc.
For example:
Temperature Density Viscosity ... ...
50 0.2 0.3 ... ...
100 0.25 0.33 ... ...
The aim of the program is to read these values (several) of them, store to memory and do some sorts of interpolations.
I created a structure, each holding the properties of the material at a given temperature. I then dynamically create an array of structures based on the number of data. If I had 100 readings, I create 100 arrays to structure.
.h file
struct Material {
float temperature;
float density;
float viscosity;
};
typedef Material* MATERIAL;
The above go into the header file
.cpp file
MATERIAL* g_ptrMaterial;
void ReadFile (char* filePath)
{
vector<string> Tokens;
int i = 0;
string val;
char c;
ifstream file(filePath);
if (!file.fail())
{
g_numberOfRows = getNumberOfRows(file);
g_ptrMaterial = new MATERIAL[g_numberOfRows];
getline(file, g_fileHeader);
while (getline(file, val))
{
g_ptrMaterial[i] = (MATERIAL) malloc(sizeof(MATERIAL));
Tokens = GetTokens(val);
if (!Tokens.empty())
{
g_ptrMaterial[i]->temperature = convertToFloat(Tokens.at(0));
g_ptrMaterial[i]->density = convertToFloat(Tokens.at(1));
g_ptrMaterial[i]->viscosity = convertToFloat(Tokens.at(2));
i++;
}
}
}
else
{
cerr << "FILE NOT FOUND!";
exit(1);
}
}
vector<string > GetTokens (string val)
{
stringstream ss(val);
string temp;
vector<std::string > Tokens;
while (ss >> temp)
{
Tokens.push_back(temp);
}
return Tokens;
}
Debugging
What I did was to attach my debugger to the executable process [Tools -> Attach to Process] as it runs. I noticed that the error is triggered in the GetTokens function. It reads the first row fine i.e (50, 0.2, 0.3), but when it comes to the 2nd row it gets stuck just when about returning Tokens from the GetTokens function. What could be the problem? I guess, I'm out of my depth on this one ...
|
|
|
|
|
I did not find anything blatantly wrong with your code. The only changes I made to get it to compile in my environment were to change float to double and convertToFloat() to atof() .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Is your application multi-threaded?
This problem can occur in such application due to some conflicts between threads.
When you single step through code, the conflict may not occur.
|
|
|
|
|
I didn't explicity create any extra threads, so I'll say it's single-threaded.
|
|
|
|
|
Exactly what does filepath contain?
When running from Visual Studio, the current directory is the one containing the .sln and .vcproj files. If your filepath only contains the name ("myfile.txt"), then it must exist in that directory.
When you run outside of visual studio, the current directory is the one containing the .exe file (normally the debug or release directory) and the file would then have to exist in that folder.
It's best to specify a full path name ("c:\\mydocs\\mydata\\myfile.txt") to avoid these problems.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Thanks Karl. The filePath is the absolute path to the text file I'm accessing. Accessing the file doesn't seem to give issues both in debug and release. A section of the code checks for file failure:
if(!file.fail())
{
}
|
|
|
|
|
Good advice but I do not think that is the cause of the problem. If he was using file (the ifstream object) without first checking to see if it was valid (e.g., bad path), then an exception would be understandable.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Problem solved and in 3 ways!
1. The "Keep it Simple Stupid" Advice works! Instead of creating an array of MATERIAL i.e Material*, I simply created an array of Material, and accessed each Material by the . notation rather than the ->.
i.e.
g_ptrMaterials = new Material [g_numberOfRows];
Material mat;
mat.temperature = 200.00;
2. One can stuff the structures into a vector:
vector<Material> vctr;
Material mat;
mat.temperature = 200.00;
mat.density = bla bla;
vctr.push_back(mat);
3. Lastly I modified the initial code. I don't know why it works ...
MATERIAL* arrMaterial = new MATERIAL[g_numberOfRows];
g_ptrMaterial = &arrMaterial[0];
arrMaterial[i] = new Material;
Perhaps the problem was mixing the malloc and new allocators? I suspected the problem was with the memory allocation, when the compiler continuously indicated errors in xmemory, dbgheap, and what not. It wasn't a v e r y pleasant experience. Anyway, I went for the first option, but one can go for any of the 3 options I suppose, without any harm.
Thanks guys 
|
|
|
|
|
hi.
i work in Microsoft Visual Studio 2008 . i working in C# enviroment and creat a website project.
i want open picture with open dialog .please tell me who i can load picture with open dialog?
i am beginner .
please explain step to step.
whether i need a componet as toolbar?
please help me.
i need help body.
thank you
|
|
|
|
|
You might want to ask your question here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi!
Got Windows Vista Business as the os. Ran msdev.exe with compatibility mode for Windows 98 (with others it failed, some sketchy errors appeared).
I get this error : "The project directory no longer exists. Please choose a different directory" as i try to create a new project. The funny thing is, that I created a project earlier the day without any problems. So I tried to change directories, didn't help. Searched google for the problem - found out that "Run as administrator" should fix the problem.. it didn't.
Has anyone else run into that problem?
|
|
|
|