|
I think it will better if we can use heap allocation instead of stack for 4k, because, these 4k allocations finally leads to stack overflow. .
Ravi you can follow which ever method according to the need.
If you follow David's method then it will be less error prone and more maintainable
but enhzflep's method is much faster
Величие не Бога может быть недооценена.
modified on Friday, October 30, 2009 4:38 AM
|
|
|
|
|
I am trying to write a program as a math tutor. Can someone look at this code. I keep getting errors on int and pointer as well as telling me the switch case has illegal pointer.
Thanks, any advice would be greatful.
#include <stdio.h>
#include <stdlib.h>
#define SENT 4 //"Quit" menu choice
void DisplayMenu (void);
void GetMenuChoice (void);
void Gen2Rand (int*r1, int*r2);
void DrillOneProb (int*c, int*r1, int*r2);
int main (void)
{
int c;
int r1,
r2;
}
void DisplayMenu (void)
{
printf("MENU OF OPERATIONS\n\n");
printf("1. Addition.\n");
printf("2. Subtraction.\n");
printf("3. Multiplication.\n");
printf("4. Quit.\n\n");
}
void GetMenuChoice (void)
{
int c;
printf ("Enter the number of the operation to try (1-4):\n");
scanf ("%d", &c);
while
(c<1 || c>SENT)
printf("\aInput value is out of range.\n");
}
void Gen2Rand (int *r1p, int *r2p)
{
int c;
c=0;
if (c>=1 && c<SENT)
int r1;
int r2;
r1 = 2 + rand() %11;
r2 = 2 + rand() %11;
*r1p = r1;
*r2p = r2;
printf("Program complete\n");
}
void DrillOneProb (int *c, int *r1, int *r2)
{
int CorAns,
Reply;
{
printf("\nWhat is %d", & r1);
r1 = 2 + rand() % 11;
}
switch (c);
{
case '1': 1 = +; break;
CorAns = r1 + r2;
case '2': 2 = -; break;
CorAns = r1 - r2;
case '3': 3 = x; break;
CorAns = r1 x r2;
}
printf("%d ? %d\n", r2, Reply);
if
Reply = CorAns
{
printf("Yes, that is correct. Good Job!");
}
else
printf("No, the correct answer is: %d", CorAns);
printf("\n\n");
return (c);
print_menu();
return (0);
|
|
|
|
|
kbury wrote: switch (c);
This must be switch (c) without the ;
I also believe that it must actually be switch (*c)
|
|
|
|
|
Thanks, I just changed and it fixed that part.
|
|
|
|
|
kbury wrote: 1 = +;
kbury wrote: 2 = -;
kbury wrote: 3 = x;
kbury wrote: CorAns = r1 x r2;
kbury wrote: if
Reply = CorAns
I think you should read very carefully a syntax reference of the C programming language.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I am only trying to follow a flow chart given and it is very confusing. Thank you
|
|
|
|
|
While following the flow, you shouldn't forget there is also the syntax...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I am stuck with this section of my code so far: error codes: expected int and got pointer to int and operands of = illegaltype pointer to int and int
void DrillOneProb (int*c, int*r1, int*r2)
{
int CorAns,
Reply;
{
printf("\nWhat is %d",r1); 1st error scanf("%d", r1);
r1 = 2 + rand() % 11; 2nd error
}
|
|
|
|
|
kbury wrote: printf("\nWhat is %d",r1);
change to
printf("\nWhat is %d", *r1);
kbury wrote: r1 = 2 + rand() % 11;
change to
*r1 = 2 + rand() % 11;
The above steps, however just fix compiler errors...I don't know if the semantic will be correct.
BTW what about a good C language programming book?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
change to
printf("\nWhat is %d", *r1); (I already changed this)I figured that out.
kbury wrote:
r1 = 2 + rand() % 11;
change to
*r1 = 2 + rand() % 11; (This defineately fixed this.
The above steps, however just fix compiler errors...I don't know if the semantic will be correct.
switch (c)
{ (states that this is illegal type pointer to int in switch expression.)
case '1':
printf("+");
CorAns = r1 + r2; (operands of + have illegal of 'pointer to int' and 'pointer to int')
break;
|
|
|
|
|
kbury wrote: CorAns = r1 + r2;
change to
CorAns = *r1 + *r2;
The real solution, however, would be reading the f*#?n' book.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I do not believe that has been in any of the chapters that we have read so far, but I will look again at the latest chapter because each assignment is associated with that chapter.
|
|
|
|
|
|
I guess you're able to guess now.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I am developing an application with three splitter panes, leftpane,right pane and bottom pane.
leftpane consists of a tree control, by clicking on the tree item, correspoding Dialog displayes in the right pane. For one tree item, by selecting it , i need to display another application by running winExec(), in right pane. I am facing problem at fitting this result application in the rightpane..I have tried with variuos Show window parameter for Winexec() call, but i failed.
thanks,
hema.
|
|
|
|
|
WinExec() spawns a new process.
If you want to show that in another application you need to create a relationship between the two applications.
You can do that using SetParent[^] and then use MoveWindow[^] to place it correctly in the right pane.
|
|
|
|
|
thanks for the reply..I will try it today..thanks a lot.
hema.
|
|
|
|
|
Hello people,
I am trying to make an application with in- and output. Input by textboxes and output by writing it to a file.
I succeeded to get text from a TextBox^ and put it in a RichTextBox^. No problem.
I succeeded to use fstream to 'print' data (string) to a file.
Now I want to combine these by using a vector<string>.
The problem I am facing is that if I do: fout << textBox->Text; that I get the following error:
1< d:\stageappvc\terminalapp\terminalapp\Form1.h(185) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'System::String ^' (or there is no acceptable conversion)
1< C:\Program Files\Microsoft Visual Studio 9.0\VC\include\ostream(653): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)
If I want to write the
textBox->Text to my vector. I get the following error:
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(194) : error C2664: 'std::vector<_Ty>::push_back' : cannot convert parameter 1 from 'System::String ^' to 'const std::string &'
I tried to find out what this String^ actually is - but I could not find an accurate answer. I also tried:
textBox->Text.toString() which failed too.
Is anyone able to help me with this? I tried to find examples of how to put TextBox data in a string, but I couldn't find anything useful...
Kind regards,
Mikki Weesenaar
|
|
|
|
|
Don't use "System::String" instead use "std::string"
|
|
|
|
|
I have:
std::vector<string> textCode;
private: System::Windows::Forms::RichTextBox^ textBox;
private: System::Windows::Forms::TextBox^ invoerVeld;
textBox->Text += invoerVeld->Text + "\r\n"; < works fine
textCode.push_back(textBox->Text); < no-go
textCode.push_back(invoerVeld->Text);
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(194) : error C2664: 'std::vector<_Ty>::push_back' : cannot convert parameter 1 from 'System::String ^' to 'const std::string &'
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(195) : error C2664: 'std::vector<_Ty>::push_back' : cannot convert parameter 1 from 'System::String ^' to 'const std::string &'
So I think I cannot just use string in stead of String. Its a native thing of the TextBox and RichTextBox. I guess... Or if Im wrong, correct me 
|
|
|
|
|
I got this from MSDN -
String^ c = gcnew String("Change Me");
std::string str1 = (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
std::wstring str2 = (const wchar_t*)(Marshal::StringToHGlobalUni(s)).ToPointer();
|
|
|
|
|
I dont see the relation between the first line and the other two.
And I need it otherwise.
I have a String^ (coming from textBox->Text) and I want to store this in a string (which I have in a vector).
|
|
|
|
|
The first line creates a String^. I believe you already have that in textBox->Text.
The second line converts that to a string.
The third line converts that to a wstring.
What else do you not see?
|
|
|
|
|
I guess I need the second then.
Currently I have
std::string str1 = (const char*)(Marshel::StringToHGlobalAnsi(textBox->Text)).ToPointer();
But it gives me the following errors:
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C2653: 'Marshel' : is not a class or namespace name
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C2228: left of '.ToPointer' must have class/struct/union
1> type is ''unknown-type''
1>d:\stageappvc\terminalapp\terminalapp\Form1.h(200) : error C3861: 'StringToHGlobalAnsi': identifier not found
So I tried to #include <marshal>, but that didn't work either.
How can I use this function?
And by the way - thanks for your fast replies 
|
|
|
|
|
Typo
It should be Marshal .
You got it wrong there.
Look at my posting.
|
|
|
|