|
i think it right im just checking...
and i did copy it and paste it right...
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
int n, temp, count0 = 0, count1 = 0, count2 = 0, count3 = 0, count4 = 0, count5 = 0, count6 = 0, count7 = 0, count8 = 0, count9 = 0;
int main()
{
cout << "Enter the number to be evaluated." << endl;
cin >> temp;
while (temp != 0){
n=temp%10;
switch(n){
case 0: count0++;
break;
case 1: count1++;
break;
case 2: count2++;
break;
case 3: count3++;
break;
case 4: count4++;
break;
case 5: count5++;
break;
case 6: count6++;
break;
case 7: count7++;
break;
case 8: count8++;
break;
case 9: count9++;
break;
}
temp = temp / 10;
}
cout << " Answer is " << endl;
if(count0>0)
cout<< "0" << " " << count0 << endl;
if(count1>0)
cout<< "1" << " " << count1 << endl;
if(count2>0)
cout<< "2" << " " << count2 << endl;
if(count3>0)
cout<< "3" << " " << count3 << endl;
if(count4>0)
cout<< "4" << " " << count4 << endl;
if(count5>0)
cout<< "5" << " " << count5 << endl;
if(count6>0)
cout<< "6" << " " << count6 << endl;
if(count7>0)
cout<< "7" << " " << count7 << endl;
if(count8>0)
cout<< "8" << " " << count8 << endl;
if(count9>0)
cout<< "9" << " " << count9 << endl;
return 0 ;
}
|
|
|
|
|
Hello all,
small problem with a simple app.
Its a simple Mp3 player app (simultation only). I have an MP3 Class that appears to load fine. It crashes out when I call the PrintMP3Details() function in Mp3.h. I get part of the output ie:
I'd really appreciate any help that anyone could provide - I've asked my lecturer four times over the past 7 days and he hasn't even replied...
Thanks in advance - Much appreciated.
"
Track 0 Contains:
Artist : BOMBS OUT HERE.....
"
MP3Player.Cpp
#include <fstream><br />
#include <iostream><br />
#include "mp3.h"<br />
<br />
using namespace std;<br />
int main (void)<br />
{<br />
int length, count, iNo, menu, loop;<br />
char str[80], fil[80], track[80], artist[80];<br />
count = 0;<br />
string filename;<br />
cout << "Welcome to the MP3 player" << endl;<br />
cout << "please enter filename (playlist.txt is default)" << endl;<br />
cin >> fil;
ifstream in(fil);
if(!in)
{ <br />
cout << "Cannot open file.\n" << endl; <br />
} <br />
while(!in.eof())
{<br />
in >> artist;
in >> track;
in >> length;
count++; <br />
} <br />
cout << endl;<br />
iNo=count;
<br />
cout << endl <<"File contains " << count << " files." << endl;
in.close();
Mp3 *Playlist[iNo];
count = 0;
ifstream in2(fil);
if(!in)
{ <br />
cout << "Cannot open file.\n" << endl; <br />
} <br />
cout << "marker " << endl;<br />
while(!in.eof()) <br />
{<br />
in2 >> artist;
in2 >> track;
in2 >> length;
count++; <br />
Playlist[count] = new Mp3(artist, track, length); <br />
cout << count << " contains " << artist << track << length << endl; <br />
} <br />
cout << endl;<br />
in.close();<br />
<br />
<br />
<br />
<br />
while (menu !=0){<br />
cout << "Please select from the following..." << endl<br />
<< "1) Print playlist (currently loaded)" << endl<br />
<< "0) Close MP3 player " <<endl << endl;<br />
cin >> menu;<br />
cout << endl; <br />
<br />
switch (menu)<br />
{<br />
case 1:<br />
for (int loop=0; loop<iNo;loop++)<br />
{<br />
cout << "Track " << loop << " Contains : " << endl;<br />
Playlist[loop]->PrintMP3Details();<br />
cout << endl << endl;<br />
}<br />
break;<br />
<br />
case 2:<br />
break;<br />
return 0; <br />
}
}
}
MP3.h
<br />
#include <fstream><br />
#include <iostream><br />
using namespace std;<br />
<br />
class Mp3<br />
{ <br />
private<br />
:<br />
string Artist;<br />
string Track;<br />
int Length;<br />
<br />
public:<br />
<br />
Mp3::Mp3(string Nartist, string Ntrack, int Nlength)<br />
{<br />
Artist = Nartist;<br />
Track = Ntrack;<br />
Length = Nlength; <br />
}<br />
<br />
string GetArtist()const {return Artist;}<br />
string GetTrack()const {return Track;}<br />
int GetLength()const {return Length;}<br />
<br />
void SetArtist (string strArtist) {Artist = strArtist;}<br />
void SetTrack (string strTrack) {Track = strTrack;}<br />
void SetLength (int iLength) {Length = iLength;}<br />
<br />
void PrintMP3Details() <br />
{<br />
cout << "Artist : " << Artist << endl<br />
<< "Track : " << Track << endl<br />
<< "Length : " << Length << endl;<br />
}<br />
};
|
|
|
|
|
I think the problem is the following:
count++;
Playlist[count] = new Mp3(artist, track, length);
Try this:
Playlist[count] = new Mp3(artist, track, length);
count++;
Or this:
Playlist[count++] = new Mp3(artist, track, length);
The first is wrong because you start by filling in Playlist[1] instead of PlayList[0] . Also at the end you will be filling in slot Playlise[iNo] , which does not exist. As a further check in your loop, you may what to use while( !in.eof() && count < iNo ) as additional safety; although the way it is written now, that will not help.
The actual cause of an error is not always reported when it occurs, so remember to work backwards from the error (what happen before it).
P.S. Prefer ++count to count++, because if those operators are ever overload the difference will give you headaches.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
If you want to play mp3 files you can also use of MCI functions.
|
|
|
|
|
Basically what I am trying to do is have two text strings pop in text boxes (CEdit) for the user when they open a dialog box. The problem is that when you call domodal, all control transfers to the dialog box, so everything has to be done before the call. In the past I have just set a flag in the dialog box class to let it know that something needs to be loaded, and placed the information there beforehand, and then called domodal. OnInitDialog gets called when the dialog pops up, checks for the flag, and loads whatever. It seems kind of messy though. Is there another more elegant way to do it? Is there some way I can modify DoModal to accept arguments?
|
|
|
|
|
have you seen This[^] article ?
|
|
|
|
|
Along these same lines, do you know how to put carriage returns into the CEdit? Yeah, I know, noob question, but I haven't worked much with CStrings and CEdit controls, and I just realized that putting a "\n" into a char buffer then converting it to a CString won't work in a CEdit...how do I do this?
|
|
|
|
|
|
that did the trick...thanks...seems counterintuitive, like I was programming for unix or something...I never even would have guessed that in a million years...
|
|
|
|
|
Also, a totally unrelated way of doing this, but may be of use if you're using a DLL, is to create a shared data segment with #pragam data_seg() and put in a global variable in there which will keep track of the number of instances of subscribers to the DLL. Of course your program will have to import the DLL etc, which is not preferable at all, but like I said if you're already using a DLL it's another option.
|
|
|
|
|
globals are most of the time bad, and can be avoided using OOP data members.
|
|
|
|
|
I made that post in the wrong thread...my bad
|
|
|
|
|
Right now, We have a ClxThreadClass that provides the capablity to create single worker thread for the class that inherits it. The function below shows the class member function that creates and starts the new thread. The desire worker code reside in _ThreadFunc.
<br />
<br />
The Current working design<br />
<br />
bool ClxThreadClass::CreateNewThread()<br />
{<br />
if( m_hThread == NULL )<br />
{<br />
m_hThread = (HANDLE)_beginthreadex(NULL, 0,_ThreadFunc, this, CREATE_SUSPENDED, &uiThreadId); <br />
if ( NULL != m_hThread)<br />
{<br />
ResumeThread( m_hThread );<br />
m_bActive = true;<br />
return true;<br />
}else{<br />
m_bActive = false;<br />
}<br />
}<br />
<br />
return true;<br />
}<br />
However, We sometimes would like to use different function other than _ThreadFunc. How can we overload CreateNewThread member function to take an external and pass to beginthreadex. This external obect is not a member function of base or inherited class.
<br />
bool ClxThreadClass::CreateNewThread( void *ptr )<br />
{<br />
<br />
if( m_hThread == NULL )<br />
{<br />
m_hThread = (HANDLE)_beginthreadex(NULL, 0, ptr, this, CREATE_SUSPENDED, &uiThreadId); <br />
if ( NULL != m_hThread)<br />
{<br />
ResumeThread( m_hThread );<br />
m_bActive = true;<br />
return true;<br />
}else{<br />
m_bActive = false;<br />
}<br />
}<br />
return true;<br />
<br />
}<br />
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
Maybe something like this:
typedef unsigned (__stdcall *PTHREADFUNC)(void *);
...
bool ClxThreadClass::CreateNewThread(PTHREADFUNC pThreadFunc)
{
if( m_hThread == NULL )
{
m_hThread = (HANDLE)_beginthreadex(NULL, 0, pThreadFunc, this, CREATE_SUSPENDED, &uiThreadId);
...
}
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Mark Salsbery wrote: typedef unsigned (__stdcall *PTHREADFUNC)(void *);
if this function points to global function, it will work .. if it point to class member function.. then there would be some trouble.. i.e. we have to change the Funtion ptr declaration and pass the pointer of the class to that function!
|
|
|
|
|
Right. The OP stated "This external obect is not a member function of base or inherited class"
which soundedread like it wasn't a class method to me.
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Mark Salsbery wrote: he OP stated "This external obect is not a member function of base or inherited class"
which soundedread like it wasn't a class method to me.
oops my mistake.. it seems work is taking over me [ ]
|
|
|
|
|
Hi,
Can someone help me?
Im just trying to get a list of all windows users names in a local computer.
GetUserName gives us just the current user:
BOOL GetUserName(
LPTSTR lpBuffer,
LPDWORD lpnSize
);
but I dont know how can I get all the other users in the same machine.
Thanks.
|
|
|
|
|
Maybe this link will help - Users in Active Directory Domain Services[^]
I chose this link since it also has links to an "old" way to enumerate users
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
|
Is it possible to scroll a disabled listbox ? without having to create an owner drawn list.
I have a listbox that gets filled with data but its state is disabled, but I want to be able to scroll the list to see what is in there.
Or maybe I should simply reconsider the UI to allow an enabled list, but "tweaked" to make the list "disabled".
Thanks.
Max.
|
|
|
|
|
If you don't accept drag and drop, and make the list box "no selection," why disable it? The user can't do anything to it with those properties set. What are you trying to prevent that you make it disabled?
Judy
|
|
|
|
|
Yeah, I checked my code, and that's what I have to do.
Thanks.
|
|
|
|
|
Hi to Every one.
I need authentication details. Could any one please kindly helpme in this.
What is authentication, and how to check this authentication. How to use SSL concept in the Email sending program. please help me. this is urgent for me.
Nice talking to you. If you judge people, you have no time to love them. -- Mother Teresa
|
|
|
|
|