Thank you mcco for providing me the definition of RECT structure
kindly provide me the values (numbers), It seems that your expression evaluates to zero thats why I've asked to provide me the values not the RECT members. :).
Thank you mcco for providing me the definition of RECT structure
kindly provide me the values (numbers), It seems that your expression evaluates to zero thats why I've asked to provide me the values not the RECT members. :).
What are the values of RECT members?
bool, true, false are already keyword in C++. you don't need to define enum for it.
I've few questions,
FrameVisitor::FrameVisitor()
{
Frame();
frames = get_frames(myfile);
}
you have passed 'myfile' as a parameter in fstream where it is defined?
change the following Code.
list<Frame> FrameVisitor::get_frames(fstream& myfile)
{
char * memblock = new char [4]; //1º 4 bytes da frame...header.
char * start = memblock;
int i = 0;
char c;
list<Frame> lst;
...........
}
// to the below one.
list<Frame> FrameVisitor::get_frames(const char* myfilePath)
{
fstream myfile(myfilePath, ios::in);
char * memblock = new char [4]; //1º 4 bytes da frame...header.
char * start = memblock;
int i = 0;
char c;
list<Frame> lst;
...........
}
Try to pass the filePath not the streams between functions
just open the stream where required and close it after using.
as far as the problem is concerned there is no copy constructor defined for streams, whenever pass by value they'll cause problems.
check your code of class frame as well. rather than storing the stream as a member keep the file path as a member.
Hope this helps.
Read the following Link Carefully and check for MACRO & GUID that needs to be defined in case of XP, I am assuming that you are good in understanding msdn doc. If you still find it difficult to implement I will provide you the sample.
http://msdn.microsoft.com/en-us/library/bb773352(VS.85).aspx
Hope the above link helps.
Hi,
why you've called LoadBitmap(...) in WM_CREATE message? I am sure your problem will be resolved if you change WM_CREATE to WM_INITDIALOG.
further you should learn and understand the difference between WM_CREATE & WM_INITDIALOG.
yes Its seems fine with a cursory look.
Good luck (Y).
try the below one
//HANDLE hPort = CreateFile("COM1", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
HANDLE hPort = CreateFile(TEXT("COM1"), GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
Hope the above help, you didn't ask what is LPCWSTR ok :). So I am providing the solution only :P.
i) create an event and check that event in the child thread
ii) signal the event from main thread when you want to exit
iii) call UnhookWindowEx() and release resouces in the child thread.
psudo code
LONG WINAPI ThreadFunc(LPVOID arg)
{
HANDLE hEvent = OpenEvent(...,"ChildEvent");
// Perform Coding.
// here you can check whether the event is signalled or not.
WaitForSingleObject(hEvent, INFINITE);
}
int main ()
{
// .. Something like below
HANLDE hEvent = CreateEvent(...);
HANDLE hThread = _beginthreadex(...., ThreadFunc);
// perform the coding of main thread.
// Signal the Event, if the child thread is still running.
GetExitCodeThread(hThread, &dwExitCode);
if (dwExitCode == STILL_ACTIVE)
SetEvent(hEvent);
// still for the safe side
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
CloseHandle(hEvent);
}
Well in the ThreadFunc I've called the WaitForSingleObject(..., INFINITE) you must know how to change it to wait for the specified Time, if you are not willing to wait synchronously (INFINITE LY).
Another Way is use the SendMessage Or PostMessage API.
The Below Code might Help just remember MessageBox Returns the Value just store that Value and then Process that response rather than calling the message box again and again.
int nResponse = MessageBox(NULL, TEXT("Hello, World"), TEXT("Say Yes No Cancel"), MB_YESNOCANCEL);
if (nResponse == IDYES) {
MessageBox(NULL, TEXT("Hey You Pressed Yes!"), TEXT("Wow! Got It"), MB_OK |MB_ICONEXCLAMATION);
}
/*else if(...) {
}
else if (...) {
}*/
One more thing why if (....) and if (....) two times, if you notice your code, you'll find one more thing
you check the first condition then again you check for some other condition.
why is that so, logically and as per the requirement, you just need to show the form & store it response & then process that response rather than calling the MessageBox API again and again.
Hope this might help
Simple replace
for (last = 1 ; last <= first; last++)
with
for (last = first ; last >=1; --last)
replace the above line and every thing is fine.
What about Buffer Overflow? :P
Hi Laid
Thanks for your reply
This is what I have
auto_ptr<SYS_CORRESP_STRUCT> p_str_Corresp = new (SYS_CORRESP_STRUCT);memset(p_str_Corresp.get(),'\0',sizeof(SYS_CORRESP_STRUCT));
conObj.CopyToDceSYS_CORRESP_STRUCT(p_str_Corresp.get(),pStrCorresp)
and then possible have a constructor to do the copying likeSYS_CORRESP_STRUCT::SYS_CORRESP_STRUCT(SysCorrespStruct*)
{// code of void CCaslifUtility::CopyToDceSYS_CORRESP_STRUCT() goes here - or just call it
}
also
do u see a potential bug when strcpy() is used instead of std::string types ??Thanks
Hi ronan,
Basically std::string are preffered over char* due to several reasons you can read many articles on that but again if you can't change it from char* to std::string you can write the adapter for SYS_CORRESP_STRUCT class or you can use the handle body ideom in this case its totally up to you and the scenario. because RPC requires marshaling so some libraries of RPC requires char* instead of std::string and if you are getting the class SYS_CORRESP_STRUCT from that lib you can better write the adapter for better manageability or you can keep it as it, as far as strcpy is concerned I don't recommend you to use strcpy you should use strncpy why ? read about buffer overflow exploit :). and I don't know why you write the strcpy as follows. strcpy((char *)output->record_type,(char *)input->recordType.c_str());
the second parameter of strcpy takes const char* and string function c_str() returns the const char* so no need to cast. if you replace the above call to strncpy if you're not intended to use the strings. then use the following call
…
The Question is where you've Created the Test Folder. Place with your code files. it will identify the header file in that folder then.
Basically using operator new for memory allocation has nothing to do with the smart pointers (auto_ptr or shared_ptr), the purpose of auto_ptr is to encapsulate the naked pointer and release the memory automatically when it exists from scope basically there are several objectives of smart pointers. among those mostly used are.
i) ownership
ii) reference counting
in your case I think you just need the wrapper to exclude the explicit delete call, you can write the wrapper like auto_ptr in more appropriate way which most suited your needs and scenarios (multithreaded or not). otherwise check for the auto_ptr implementation again be careful if you pass this pointer to some functions as I told you if auto_ptr is implemented by your compiler as ownership transfer then you must always pass (auto_ptr<T>&) to any function (i.e. reference to auto_ptr) otherwise you'll lost the ownership from main function. Its good to use the Auto pointer
Read any good article of Auto_ptr, but keep in mind the different between delete[] & delete operator provided by your auto pointer implementation.
Hope this helps?
Try Reading Socket Programming.
what you are actually doing is creating a server listening on Port, this can be achieved using WinSock on windows Plateform, same can be done on linux using the socket API defined for linux.
int main ()
{
// Initialize the Socket Environment.
// Create Server side Socket.
// Define Address information & Port.
// Bind to that information.
// Start Listening on specified information.
// Upon Connection Get the Information.
// Process the Information.
return 0;
}
hope the above alogirthm might help you.
check the following program
char CalculateGrade (const double percent)
{
if (percent >= 90)
return 'A';
else if (percent >= 80)
return 'B';
else if (percent >= 70)
return 'C';
else if (percent >= 60)
return 'D';
else if (percent >= 50)
return 'E';
else
return 'F';
}
double CalculateAnswers (const string& studentsResponse, const string& answers)
{
double score = 0;
for (size_t i=0; i< answers.length (); ++i)
{
if (studentsResponse[i] == answers[i])
{
++score;
}
else
{
--score;
}
}
double percent = (score/answers.length ())*100;
return percent;
}
int main ()
{
ifstream inputFile ("C:/inputFile.txt");
ifstream answersFile ("C:/answers.txt");
if ( !inputFile.is_open ())
{
cout<<"File not opened"<<endl;
}
if (!answersFile.is_open ())
{
cout<<"Answers File not Opened"<<endl;
}
string answer; //read from file...
// Reading the answer from answers File.
std::getline (answersFile, answer, '\n');
answersFile.close ();
answersFile.clear ();
// Reading the Input File...
string line;
string userId, studentResponse;
while (std::getline (inputFile,line, '\n'))
{
// you have student's answer in variable -->studentResponse, and id --> userId.
std::stringstream inStream(line);
inStream>>userId;
inStream.get();
std::getline(inStream, studentResponse, '\n');
//Compare the answers.
double score = CalculateAnswers (studentResponse, answer);
// Calculate the Grade.
char grade = CalculateGrade (score);
cout<<"The Student :"<<userId<<" got "<<grade<<" grade"<<endl;
}
inputFile.close ();
return 0;
}
The answers File contains answers in the form
TFTFTFFFF.
exactly xsoniccrackersx, I tried to provide you the strings separately now you should modify the algorithm yourself or atleast paste you efforts :).
Hope the following code. helps.
int main ()
{
ifstream inputFile ("C:/inputFile.txt");
if ( !inputFile.is_open ())
{
cout<<"File not opened"<<endl;
}
string line;
string userId, answers;
while (std::getline (inputFile,line, '\n'))
{
std::stringstream inStream(line);
inStream>>userId;
std::getline(inStream, answers, '\n');
cout<<"The userId is :"<<userId<<" and answers are: "<<answers<<endl;
}
inputFile.close ();
return 0;
}
Narue its a part of utility.h in VS2008 and in Utility.h and xstring on VS2005.
set the prototype of functions
like this
void setW();
void setL();
replace above two with
void setW(double num1)
void setL(double num2)
remember to add semicolon where required.
dougy83
thanks, I know this is the portable and most suitable way to swap, there exists several other swapping techniques, but I was concentrating on technique adopted by Yellowdog428. I want him to find out this technique himself.
Thanks anyway.
Lets do some sorting.
First of all the sorting technique you are using is sort by swapping. famous as a bubble sort.
before sorting lets improve your code. which is more strutured
Why are you keeping the two related things separate? why don't keep these two things rainfall & month as an aggregate. here comes structure.
struct RainFallInfo {
double rainFall; // stores information about rain
char month[10]; // stores information about month.
};
how to sort this.
is simple
void Swap (RainFallInfo& first, RainFallInfo& second)
{
// swapping technique...
RainFallInfo temp;
temp.rainFall = first.rainFall;
strcpy (temp.month, first.month);
first.rainFall = second.rainFall;
strcpy (first.month, second.month);
second.rainFall = temp.rainFall;
strcpy (second.month, temp.month);
}
void Sort (RainFallInfo rInfo[], int MONTHS)
{
for (int i=0; i<MONTHS; ++i)
{
for (int j=i+1; j<MONTHS; ++j)
{
if (rInfo[i].rainFall> rInfo[j].rainFall)
{
Swap(rInfo[i], rInfo[j]);
}
}
}
}
Hope you understand.
where you lack can be seen by comparing my sort function with yours.
like these.
startIndex < (MONTHS - 1); // should be replaced by MONTHS
strcpy is required to copy char array to other char array.
Hope this helps...
if you don't know references, 'RainFallInfo&' you can replace this by RainFallInfo* and do the same.
what it actually does.
Let me tell you what it actually does, and what it should do
first what it does
template <class T>
void myVector<T>::grow(){
while(size >= capacity) {
T* temp;
temp = data;
capacity *= 2;
data = new T[capacity];
for(int i = 0; i < size; i++)
{
data[i] = temp.data[i];
}
delete []temp;
}
}
basically T refers to int in your case now the new code becomes.
void myVector<int>::grow(){
while(size >= capacity) {
int* temp;
temp = data;
capacity *= 2;
data = new int[capacity];
for(int i = 0; i < size; i++)
{
data[i] = temp.data[i];
}
delete []temp;
}
}
lets move from bottom up manner you'll recognise yourself.
what does your sentence data = temp.data means ???
int is a primitive type not a aggregate type, so a compile error is there.
now you know what should be change.
as above.
string s; cin >> s;
for example, if the user enters Orange, i want it to convert to orange.
please advise what i should do.
thanks in advance
Check out this code
std::string str;
cin>>str;
transform(str.begin(), str.end(),str.begin(), tolower );
cout<< str;
The stack is a lifo(last in first out) based sequential structure. I think you don't need a double link list to implment it, you can implement lifo based list directly.
struct Node {
int m_iVal;
Node* m_pNext;
Node(int const& iVal,m_pNext=0)
}
if you've used the stack it provides three basic as well as standard functionality
push() to push the element on the top of stack
pop() to pop the element from the top
top() returns the top element;
there is no need for display function in the standard stack.
if you need that function
you should have written like that
void display()
{
//it uses
while(HEAD)
{
while(HEAD)
{
cout<<HEAD->top()<<endl;
HEAD->pop();
}
}
Your push function takes the pointer as an argument there is no need for that, and remove the friend from there.......
push should be member function.~! i.e. void push(int value) remember this pointer is always passed quitely to member function so no need to pass explicity and declare it as a friend and you are violating the OOP concept encapsulation by doing this.why you've used static counter.............if you declare push as a member function there is no need for that. also why don't you utilize HEAD variable for this.
your push function should be like this.
void push(int value)
{
HEAD= new Node(value,HEAD);
//or its also fine
/* if(HEAD==0)
HEAD= new Node(value);
else {
Node* temp = new Node(value)
temp->m_pNext=HEAD;
HEAD=temp;
}*/
}
you didn't include …