|
kfaday wrote:
arch=fopen(tempf,"r+");
What is this? The first parameter to fopen() is a const char* filename, and the return value is a FILE* . Something like:
tempf = fopen("myfile.txt", "r+");
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I am write a program that has two buttons. The first button would read an int value from a textbox and loads the value into an array. Both of the buttons should take the program execution from the button presses to a single method. The array holding the data should be declared locally in this method. The array is 50 elements long. When Calculate Average button is pressed,and pass the array and the count of the number of items in the array to a separate method that will perform the averaging and display the average value of the array in a label.
Wow, I hope you not a sleep after all that... Okay, I have the buttons,the textboxes, the only problem I am having and need help with is taking the input from the textbox, then assign it to array and the caculate the average.. Thank You for the Help....
|
|
|
|
|
You need to pass the array as a pointer, and then you're right, you need to pass a count as well. Or you can use a vector, which you can pass by reference.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I am stuck. I can not get the average if the inputs and I am not sure if the value are add up. Here is what I have so far... If you need to see my whole program just let me know.
void MyForm:: Btn1_Clicked(Object* sender, EventArgs* e)
{
int i,sum;
int* average = new int[50];// Create an array dynamically pg.234
String* average1 = VoltsTextBox->Text;
int val = Int32::Parse(average1);
for(i=0; i<50; ++i)
{
average[i];
}
for(i=0; i<50; ++i)
{
sum = sum + average[i];
}
int ave = sum/i;
String* ave2= ave.ToString("F3");
CurrentTextBox->Text= ave2;
}
|
|
|
|
|
I would expect something like,
class MyForm
{
private :
...
int values [ 50 ] ;
int value_count ;
public :
MyForm () : value_count ( 0 )
{
...
}
void Btn1_Clicked(Object* sender, EventArgs* e)
{
if ( value_count < 50 )
{
values [ value_count ] = GetValueFromBox () ;
++value_count ;
}
}
void Btn2_Clicked(Object* sender, EventArgs* e)
{
int sum = 0 ;
for ( int c = 0; c < value_count; ++c )
{
sum += value [ c ] ;
}
SetValueInBox ( sum / value_count ) ;
}
...
} ;
But if I were doing it I'd use a vector so as not to have any arbitrary limit on number of values.
The code above doesn't fit your requirements, but your requirements seem perverse. I don't understand why you are asked to make the array local to the method, this just seems to be requiring bad code. You would have to make the array and the count static, and then how does the 'average' button method know how to find the data?
Paul
|
|
|
|
|
This will help me finish the class project. There are few people loss in this class. Well, I have about three more project to finish up on, so I know will be posting more questions. Thank You...
|
|
|
|
|
The tab order of the controls in my dialog is wrong and i can't seem to change it. I tried pressing CTRL+D and putting them in the right order but it just doesn't seem to change anything. I also tried to edit the numeric values of the resources, but again to no effect And i really would like them to be in the right order. I also tried deleting them all and creating them again the right order, but i initially created them in the right order anyhow and still no effect, the tab order just stays the same.
Anyone know how to fix this?
Thanks.
Kuniva
--------------------------------------------
|
|
|
|
|
Strange - Layout | Tab Order (Ctrl+D) works for me. Is your .rc file read-only?
Kuniva wrote:
tried to edit the numeric values of the resources
That won't help. To manually fix the tab order, edit the .rc file outside VC6 and insert the controls in your dialog in the right (desired) order.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Right now, I'm using
#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
to keep the console window from being shown. However, later in the program, I want to show the window for text input and output.
I've tried CreateConsoleScreenBuffer() and all but cant figure out how to do this.
By using the pragma, am I preventing the window from ever being shown?
If not, how do I show the console window?
|
|
|
|
|
Can't you just use AllocConsole and FreeConsole ?
Best regards,
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
Thanks for the reply.
AllocConsole() creates a new console window, but I cant print anything to it using printf or cout.
As you can see, I'm not very good with win32 console programming.
Any suggestions?
Thanks!
|
|
|
|
|
I'm not that expert with console programming too but you can try these 2 ways:
1) use the Windows functions for console writing: get a handle to the current console using the GetStdHandle function. Then use the WriteConsole function to write to it.
2) there is a way to use the freopen function and redirect all printf commands (stdout/stdin/stderr) to your new console window. You must somehow get a FILE* for the console, but don't ask me how to do this...
Best regards,
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
|
I need help with a textbox, something simple because I am a study. I have a button when selected it will call this function that will show a text. The function is below. I would like when the button is selected to call a function and the function will display a textbox that a user can input text.
void Btn1_Clicked(Object*, EventArgs*)
{
MessageBox::Show(S"Lets see if we can switch this text");
}
Thanks for the help......
|
|
|
|
|
The onclicked delegate looks okay.
Add an event to the button control and pass in that Btn1_Clicked delegate.
Kuphryn
|
|
|
|
|
Thanks Kuphryn Its works ....
|
|
|
|
|
Hi
I'm working with an ATL COM component for a simple task. I’m using ADO (classic ADO) with MFC and I do have a ATL class called “Connection” as a main connection object. Also I have another few ATL classes which are used to access each table from the database. Now I need to globalize “Connection” object’s instant (just assume it’s already instantiated) to access other objects. But I was unable to find a good way for that!
Anyone can help me?!!!!!!!!!!!!!
Thanks,
Sanjayapr
|
|
|
|
|
You can make a COM object global with CComObjectGlobal :
CComObjectGlobal<Connection> g_connection;
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
There is a saying in statistics that a million monkeys pounding on typewriters would eventually create a work of Shakespeare. Thanks to the Internet, we now know that this is not true.
|
|
|
|
|
Hi All,
Do I need to initialize in the copy constructor too?
Example:
Foo::foo()
{
*pc = new char[5];
}
Foo::foo(cont foo& f)
{
*pc = new char[5]; // Do I need to do this here too?
Strcpy(this->pc, f.pc);
}
Thanks in advance.
|
|
|
|
|
Assuming your destructor calls delete[] pc , then yes. That is the point of the copy constructor, to make a deep copy when the default behavior of a bitwise copy is insufficient.
BTW, whenever you have a copy constructor, it's a good guideline to also have an operator = as well.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
There is a saying in statistics that a million monkeys pounding on typewriters would eventually create a work of Shakespeare. Thanks to the Internet, we now know that this is not true.
|
|
|
|
|
I agree with Mike, however:
Try to avoid this if at all possible - but sometimes it isn't.
Rely upon your lower level tools to ensure copy semantics are enforced properly. In this example rather than using char* try to use std::string, doing so would mean that you wouldn't even have to write the copy constructor. Similarly, rather than using arrays, use std::vector, std::list or std::deque.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
hi guys, i am trying to read in CD info from a file and put it into an array, using a CD class. I have been working here for about 6-8 hours trying to get the input file into an array. i just need some help starting it. It needs to read 15 15 rows with 6 columns in each row. Any help???
thx a bunch.....
#if !defined(microsoft)
#include <stdlib.h>
#define cls() system ("cls");
#endif
#include <iostream>
#include <iomanip>
#include <fstream>
#include <conio.h>
#include <cstring>
using namespace std;
class CD
{
private:
int numberID1;
char nameArtist[20];
int numSongs;
char genderArtist[10];
float cdPrice;
char artistLabel[25];
char cdArray[15];
public:
CD(); // default constructor
void getData(); //getData
void reportData();
void getkeyedData();
~CD(); //destructor
};
CD::CD()//constructor
{
numberID1 = 0;
nameArtist[0] = '\0';
numSongs = 0;
genderArtist[0] = '\0';
cdPrice = 0;
artistLabel[0] = '\0';
}
CD::~CD()//destructor
{
}
ifstream infile;
ofstream outfile;
ofstream errorlog;
int main ()
{
void instructions();
int menu();
void printCDList(const CD[]);
CD myCD;
CD CDList[50];
int i;
int data_amt;
int response;
outfile.open("cdlist.txt");
errorlog.open("errorlog.txt");
arraytest.open("arraytest.txt");
do
{
char filename[80];
infile.clear();
cout << "Please enter the name of the file with the CD information in it: ";
cin >> filename;
infile.open(filename, ios::in);
}
while (infile.fail());
instructions();
infile>>data_amt;
for(i=1; i<=data_amt; i++)
{
cout << "CD #" << i <<endl;
="" mycd.getdata();
="" getche();
="" cdlist[i]="myCD;
" }=""
="" getche();
="" response="menu();
switch(response)
{
//case" 1:="" mycd.idsort();
="" break;
="" case="" 2:="" mycd.artistsort();
="" break;
case="" 3:="" mycd.getkeyeddata();
="" 4:="" mycd.changeprice();
="" 5:="" mycd.reportdata();
="" cout="" <<="" "printing="" report......"="" endl;
="" "please="" hit="" enter="" to="" finish="" report"="" 6:="" break;
}
="" return="" 0;
}="" end="" of="" main
="" *
="" }
="" if(menuagain[0]="='Y'||menuAgain[0]=='y')
" {
="" menu();
="" else
="" "thank="" you="" for="" using="" this="" program.="" goodbye!"="" endl;
="" 0;
}
="" **********************************************************************
="" function="" name:="" instructions
="" purpose:="" explain="" the="" user="" what="" program="" will="" do
="" parameters:
="" input:
="" input="" &="" output:
="" value:
="" non-local="" variables="" used:
="" functions="" called:
="" **********************************************************************
*=""
void="" instructions()
{
="" "this="" allow="" information="" a="" cd="" from="" keyboard="" and="" file."="" "it="" accept:="" "="" "the="" upc="" code="" on="" cd,="" artist's="" name,="" gender="" artist,="" number="" songs="" price="" label="" that="" released="" cd"="" endl;
}
int="" menu()
{
="" int="" ans;
="" do="" cls();
="" cout<<"choose="" one="" following="" options:"<<endl;
="" cout<<"1.="" sort="" display="" list="" cd's="" by="" id="" number"<<endl;
="" cout<<"2.="" artists="" name"<<="" cout<<"3.="" new="" keyboard"<<endl;
="" cout<<"4.="" change="" cd's"<<endl;
="" cout<<"5.="" create="" report="" sorted="" cout<<"6.="" exit="" program"<<endl;
="" cin="">> ans;
}
while((ans<1)||(ans>6));
return ans;
}
|
|
|
|
|
Welcome to CodeProject, pvparks. Your post is unfortunately too long and hard to read so I doubt you'll get much help.
You need to do a few things. First, put <pre>...</pre> tags around the code to preserve spacing. It's also too much code, you need to narrow it down to just the part that isn't working. Finally, explain what's going wrong. Is it crashing? Giving you the wrong output? Formatting the hard drive?
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Pinky, are you pondering what I'm pondering?
I think so Brain, but if we shaved our heads, we'd look like weasels!
|
|
|
|
|
Michael Dunn wrote:
Finally, explain what's going wrong. Is it crashing? Giving you the wrong output? Formatting the hard drive?
That'd be funny
How do I print my voice mail?
|
|
|
|
|
Hockey wrote:
That'd be funny
Not for him...
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|