|
i dont know... i am really comfused after this.cant find it out.i havent understand the theory very well.
thanks for your help! Really!
you cant tell me the solutions for sure? I will learn from it i am so close but nothing.In 2 hours i have to give it! please ?! and with do while?
|
|
|
|
|
Someone has given you the answer
I'm sorry, this is as simple as it gets. If you can't grasp it, you need to go and talk to your teacher, perhaps you're not cut out for this course, or perhaps you need some one on one attention from your teacher to get you started on how this all works.
In any case, C is as hard a language as you're likely to learn ( although this example is so simple that it's fundamentally the same in any language, my advice would stand even if you were learning VB )
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I have been the one who has given the answer. After all the messages and the petition of:
you cant tell me the solutions for sure? I will learn from it i am so close but nothing.In 2 hours i have to give it! please ?!
I think he has understand that should learn harder. I'm agree with you, but every beginning is difficult.
@wakenDJ
try to get some manuals from the net, there are terabytes about C and C++. Make lots of tries and error programms, and ask whenever you have problems or doubts, but don't ask for the solutions of your homeworks because you will maybe have them, but you will never learn. It's up to you to go on and learn programming, or just pass a course without profits for you.
Edited
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
But this will give:
**********
**********
**********
and so on, as output. And that was not the question.
There principle is this, but there is two ways to do it.
1)
int i = 0, j = 0;
for (i = 1; i <= 10; i++)
{
for (j = 1; j <= i; j++)
printf ("*");
printf ("\n");
}
the first loop determines the line and the number of stars, and the second wirte all the stars from 1 till the number of the line.
2)
int i = 0, j = 0;
for (i = 1; i <= 10; i++)
{
for (j = 1; j <= 10; j++)
{
printf ("*");
if (j == i)
break;
}
printf ("\n");
}
This is more or less the same as the first one, but putting both limits to 10 and breaking the second loop when it reaches the number of the line (and consecuentally the number of stars that should be written)
EDIT: With the do... while is more or less the same, in my previous message (chronologically, but below this one in forum-space) I have written you the differences and structure of for, while and do.. while.
Just translate it to whatever you want to use and we correct you
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
Hi, try this
#include
main()
{
int a;
scanf("%d",&a);
printf("Hello\n");
getchar ();
}
or
#include
main()
{
int a;
printf("Hello\n");
scanf("%d",&a);
}
about the question of the for...
for (int i = 0; i < nMax; i++)
//do something
is the same as
int i = 0;
while (i < nMax)
{
//Do something
i++
}
and the difference with
int i = 0;
do
{
//do something)
i++;
} while (i < nMax)
is the this last one ALWAYS execute code at least one time before checking the condition.
About your homework... its your homework, so u have to learn with your own effors. We can and will help you, but not give you the written code
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
Instead of running it from within the IDE, open a command prompt first and run it from there.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
i need to write these commands only and run:
#include<stdio.h>
main()
{
printf("Hello\n");
}
A step by step tutorial on Visual Studio 2005 please...
Dont need other libraries such stdafx.h and other code such :
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
Just want to run the command above without any errors just i did in my lesson ,but in Visual Studio 6
Thanks
|
|
|
|
|
The code you have given is in C platform but is acceptable in C++. No more stories dear...
Open Visual C++ from your machine.
Create new source file and save it using appropriate name.
Type in the following code:
#include<iostream>
using namespace std;
void main()
{cout<<"Hello\n";
}
amets is a young talented and enthusiastic upcoming software developer in one of the kenyan public universities.Computing problems are no more with stema. Try him and you will never regret.
|
|
|
|
|
I'm trying to get my code to create a thread pool class that fires off 5 threads and prints the instantiation sequence of the threads right before terminating by raising an event from the spawned thread itself, but I'm getting the following linker errors when compiling with VC8:
1>EventHandler.obj : error LNK2019: unresolved external symbol "private: static class CSource * CThreadPool::source" (?source@CThreadPool@@0PAVCSource@@A) referenced in function "private: static unsigned int __stdcall CThreadPool::DoWork(void *)" (?DoWork@CThreadPool@@CGIPAX@Z)
1>EventHandler.obj : error LNK2019: unresolved external symbol "private: static class CReceiver * CThreadPool::receiver" (?receiver@CThreadPool@@0PAVCReceiver@@A) referenced in function "public: __thiscall CThreadPool::CThreadPool(class CSource *,class CReceiver *)" (??0CThreadPool@@QAE@PAVCSource@@PAVCReceiver@@@Z)
The below is my source code:
#include <stdio.h>
#include <process.h>
#include <windows.h>
[event_source(native)]
class CSource
{
public:
__event void MyEvent(int nValue);
};
[event_receiver(native)]
class CReceiver
{
public:
void MyHandler(int nValue)
{
printf("Thread %d terminating...\n", nValue);
}
void hookEvent(CSource* pSource)
{
__hook(&CSource::MyEvent, pSource, &CReceiver::MyHandler);
}
void unhookEvent(CSource* pSource)
{
__unhook(&CSource::MyEvent, pSource, &CReceiver::MyHandler);
}
};
class CThreadPool
{
public:
CThreadPool(CSource* source, CReceiver* receiver)
{
CThreadPool::source = source;
CThreadPool::receiver = receiver;
receiver->hookEvent(source);
}
~CThreadPool()
{
receiver->unhookEvent(source);
}
void Initialize()
{
SpawnThreads();
}
private:
static CSource* source;
static CReceiver* receiver;
void SpawnThreads()
{
HANDLE hThread[5];
unsigned threadID[5];
for (int i = 0; i < 5; i++)
{
hThread[i] = (HANDLE)_beginthreadex(0, 0, &CThreadPool::DoWork, (void*)i, 0, &threadID[i]);
}
};
static unsigned int __stdcall DoWork(void* pArgs)
{
unsigned int x = 0;
for (int i = 0; i < 1000000; i++)
{
x++;
}
__raise CThreadPool::source->MyEvent(*(int*)pArgs);
return x;
}
};
int main() {
CSource source;
CReceiver receiver;
CThreadPool* threadPool = new CThreadPool(&source, &receiver);
threadPool->Initialize();
}
|
|
|
|
|
You have to initialize static members outside of the class declaration. So in a .cpp file you need something like:
CSource* CThreadPool::source = null;
or whatever it should be and of course the other static member as well.
led mike
|
|
|
|
|
It seems like the problem was that I didn't separate my .cpp and my .h when I should have, making things more confusing.
Thanks.
|
|
|
|
|
Hello,
Here is the function:
void CAssignment04View::OnPrint(CDC* pDC, CPrintInfo* pInfo)<br />
{<br />
int iRowCount = 1;
CString cNumeric;
CPen oPen;
CBrush oBrush;
CFont oTextFont;
CFont oHeadFont;
CFont oColFont;
LOGFONT lfFont;
CSize oFontSize;
COLORREF clrRef;
int iRowPos = 120;
int iTextHeight = 0;
CRect oDrawRect;
int iRecNumPos;
COleCurrency Salary;<br />
<br />
int iEmployeeNumPos; <br />
int iFirstNamePos; <br />
int iLastNamePos;<br />
int iAgePos;<br />
int iDepartmentPos;<br />
int iSalaryPos;<br />
<br />
BOOL EndOfRowset = false;
HRESULT hr;
<br />
<br />
oDrawRect = pInfo->m_rectDraw;<br />
clrRef = 0x00000000;<br />
<br />
oPen.CreatePen(PS_SOLID, 2, clrRef);<br />
pDC->SelectObject(&oPen);<br />
clrRef = 0x00C0C0C0;<br />
oBrush.CreateSolidBrush(clrRef);<br />
pDC->SelectObject(&oBrush);<br />
oHeadFont.CreatePointFont(240, "Arial", pDC);<br />
pDC->SelectObject(&oHeadFont);<br />
oFontSize = pDC->GetOutputTextExtent("HR DataBase");<br />
pDC->Ellipse(500,<br />
iRowPos - (oFontSize.cy / 2) - 10,<br />
oDrawRect.Width() - 500,<br />
iRowPos + (oFontSize.cy / 2) + 10);<br />
pDC->SetBkMode(TRANSPARENT);<br />
pDC->TextOut((oDrawRect.Width() - oFontSize.cx) / 2,<br />
iRowPos - (oFontSize.cy / 2) - 10,<br />
"HR DataBase");<br />
pDC->SetBkMode(OPAQUE);<br />
oHeadFont.GetLogFont(&lfFont);<br />
iRowPos = abs(lfFont.lfHeight) + 175;<br />
oTextFont.CreatePointFont(120, "Arial", pDC);<br />
oTextFont.GetLogFont(&lfFont);<br />
iTextHeight = abs(lfFont.lfHeight) + 10;<br />
lfFont.lfWeight = 700;
oColFont.CreateFontIndirect(&lfFont);<br />
pDC->SelectObject(&oColFont);<br />
<br />
iRecNumPos = int(oDrawRect.Width() / 17);<br />
iFirstNamePos = iRecNumPos + 50 + pDC->GetOutputTextExtent("##").cx;<br />
iLastNamePos = iFirstNamePos + 50 + pDC->GetOutputTextExtent("###########").cx;<br />
iAgePos = iLastNamePos + 100 + pDC->GetOutputTextExtent("###########").cx;<br />
iDepartmentPos = iAgePos + 150 + pDC->GetOutputTextExtent("##").cx;<br />
iSalaryPos = iDepartmentPos + 150 + pDC->GetOutputTextExtent("##########################").cx;<br />
<br />
<br />
pDC->TextOut(iRecNumPos, iRowPos, "#");<br />
pDC->TextOut(iFirstNamePos, iRowPos, "First Name");<br />
pDC->TextOut(iLastNamePos, iRowPos, "Last Name");<br />
pDC->TextOut(iAgePos, iRowPos, "Age");<br />
pDC->TextOut(iDepartmentPos, iRowPos, "Department");<br />
pDC->TextOut(iSalaryPos, iRowPos, "Salary");<br />
<br />
iRowPos += iTextHeight;<br />
pDC->MoveTo(iRecNumPos, iRowPos);<br />
pDC->LineTo(oDrawRect.Width() - iRecNumPos, iRowPos);<br />
iRowPos += 30;<br />
pDC->SelectObject(&oTextFont);<br />
iTextHeight = 20 + pDC->GetOutputTextExtent("Xy").cy;<br />
m_pSet->MoveFirst();<br />
while (!EndOfRowset)<br />
<br />
{<br />
itoa(iRowCount, cNumeric.GetBuffer(10), 10);<br />
cNumeric.ReleaseBuffer(-1);<br />
pDC->TextOut(iRecNumPos, iRowPos, cNumeric);<br />
pDC->TextOut(iFirstNamePos, iRowPos, CString(m_pSet->m_Employee_Name_First));<br />
pDC->TextOut(iLastNamePos, iRowPos, CString(m_pSet->m_Employee_Name_Last));<br />
<br />
itoa(m_pSet->m_Employee_Age, cNumeric.GetBuffer(10), 10);<br />
cNumeric.ReleaseBuffer(-1);<br />
pDC->TextOut(iAgePos, iRowPos, cNumeric);<br />
<br />
pDC->TextOut(iDepartmentPos, iRowPos, CString(m_pSet->m_Department));<br />
<br />
<br />
iRowPos += iTextHeight;<br />
iRowCount ++;<br />
<br />
m_pSet->MoveNext();<br />
if (m_pSet->IsEOF())<br />
{<br />
<br />
EndOfRowset = true;<br />
break;<br />
}<br />
<br />
<br />
}<br />
<br />
CRecordView::OnPrint(pDC, pInfo);<br />
}
Now the problem:
When you start the application you can navigate the records fine. You can then click print preview and it displays what you might expect. Now if you close the print preview window the recordset has navigated to the end. When you try to click either the << or < button it displays the following error message:
operation failed, no current record
Any suggestions what might be wrong. If you don't click the print preview button then you can navigate the records without problem.
Many Thanks.
|
|
|
|
|
For starters, here's the relevant code...
void CAssignment04View::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
BOOL EndOfRowset = false; // End of the rowset?
while (!EndOfRowset) {
// See if this is the last row.
m_pSet->MoveNext();
if (m_pSet->IsEOF()) {
EndOfRowset = true;
break;
}
}
CRecordView::OnPrint(pDC, pInfo);
}
/*
From MSDN:
If the last record is the current record when you call MoveNext, IsEOF will subsequently return nonzero. If IsEOF returns nonzero and you call MoveNext, an error occurs.
If IsEOF returns nonzero, the current record is undefined, and any action that requires a current record will result in an error.
*/
|
|
|
|
|
Thanks the advice. I don't suppose the MSDN page provided a solution to this ?
I got the code working when using OLE as my connection method using this code:
iRowPos += iTextHeight;<br />
iRowCount ++;<br />
hr = m_pSet->MoveNext();<br />
if (hr == DB_S_ENDOFROWSET)<br />
{<br />
EndOfRowset = true;<br />
break;<br />
}
However when this code is run using ODBC I get this error which I cannot fix:
error C2440: '=' : cannot convert from 'void' to 'HRESULT'
|
|
|
|
|
Lewis01 wrote: I don't suppose the MSDN page provided a solution to this ?
Did you try resetting the position to the first record before the break or something like that to set the position to a valid record before the function exits?
CRecordset::SetAbsolutePosition
Lewis01 wrote: I got the code working when using OLE as my connection method using this code:
Honestly, that code snippet makes no sense to me. What exactly is m_pSet in the context of the code snippet you just provided. I was assuming you were using a CRecordset but HRESULT is usually used with COM so I'm a little lost.
|
|
|
|
|
Lewis01 wrote: However when this code is run using ODBC I get this error which I cannot fix:
It's a compiler error, not a runtime error.
Lewis01 wrote: error C2440: '=' : cannot convert from 'void' to 'HRESULT'
Because the MoveNext() method does not return anything.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello,
I have previousy built a ODBC database application within VS2003 and was able to use the following code in order to sort the records:
m_pSet->m_<br />
m_pSet->Close();<br />
m_pSet->m_strSort = "[Col1]";<br />
m_pSet->Open();<br />
UpdateData(FALSE);
However I know have to use OLEDB solution and the method m_strSort is no longer available. Is it a matter of just a header file to get this functionality or can someone talk me through a new way of sorting records ?
Many Thanks.
|
|
|
|
|
Could you, please help me! I'm developing with VC++ 6 (WinXP SP2) and now I'm trying to find memory leaks. Internal memory leak finder doesn't provide me with sufficient information about codelines etc. that is why I tried a lot of tools. No one helps me. Here you can see an example with VLD (http://www.codeproject.com/tools/visualleakdetector.asp) tool used. Here is the output in Debug window:
<br />
........<br />
Visual Leak Detector Version 1.0 installed (multithreaded static).<br />
Loaded 'G:\WINDOWS\system32\uxtheme.dll', no matching symbolic information found.<br />
Loaded 'G:\WINDOWS\system32\riched32.dll', no matching symbolic information found.<br />
........<br />
The thread 0x8D0 has exited with code 0 (0x0).<br />
The thread 0x17C has exited with code 0 (0x0).<br />
The thread 0xD2C has exited with code 0 (0x0).<br />
The thread 0x824 has exited with code 0 (0x0).<br />
The thread 0xCFC has exited with code 0 (0x0).<br />
The thread 0x8DC has exited with code 0 (0x0).<br />
The thread 0x5F8 has exited with code 561 (0x231).<br />
The thread 0x528 has exited with code 0 (0x0).<br />
The thread 0x294 has exited with code 2 (0x2).<br />
No memory leaks detected.<br />
Visual Leak Detector is now exiting.<br />
The thread 0x470 has exited with code 0 (0x0).<br />
No memory leaks detected.<br />
Visual Leak Detector is now exiting.<br />
Detected memory leaks!<br />
Dumping objects -><br />
{60} normal block at 0x02F71790, 12 bytes long.<br />
Data: < > 90 17 F7 02 90 17 F7 02 CD CD CD CD <br />
{59} normal block at 0x02F717D0, 44 bytes long.<br />
Data: <|h a a > 7C 68 F2 02 80 61 F2 02 88 61 F2 02 10 1B F7 02 <br />
Object dump complete.<br />
The thread 0x928 has exited with code 0 (0x0).<br />
The program 'E:\Devs\Camel\Debug\Camel.exe' has exited with code 0 (0x0).<br />
As you can see, VLD is saying that there are no memory leaks (1) then internal leaks finder is saying the same (2), but then it finds two leaks. How it can be and what is the problem? This problem is regardless tool used. I just placed VLD as an example. Tools like Insure++ find nothing at all of just lines with calls to rand() or time() , which have no attitude to the problem. What can it be?
|
|
|
|
|
dum wrote: What can it be?
Disclaimer: I have no experience with other leak detector tools except what VC++ alerts me to.
In my experience, typical leaks occur when I use BSTR without a wrapper, failure to release a device context(ReleaseDC) after using GetDC(), and the obvious new/delete mismatched pairs.
You should search for the obvious sources in your code first. Any usage of a raw BSTR should be considered suspect (Not necessarily bad but at least scrutinize who "owns" the BSTR) as well as GetDC() and all memory allocation.
The execution paths should be scrutinized as posted sample code usually makes many assumptions about the success of operations to keep the snippet short and can mislead proper robust deallocation schemes. For instance, allocating and deallocating within the same scope can be dangerous if there are potential execution paths that can skip over the deallocation. Try/Catch is one of the likely places to forget alternate execution paths when allocation/deallocation is involved.
I Hope that helps.
|
|
|
|
|
The fact is that I'm developing this code for... 5 years. There have been several official releases etc. All the time I could find leaks manully or using some tools. There are no BSTR's at all and no new resources occupations. I do not know, what can it be, because I don't undestand, how memory leaks can be detected after I was reported that "No memory leaks detected"? On what stage of application's execution it caould be in this case? May be one can recomend me some outstanding tool for leaks looking up (I have tryed 5 today and no one have helped)?
|
|
|
|
|
If it helps any, I took a mulithreaded app and placed some intentional leaks in one of three of the threads. Everything appears fine until the app exits and the main thread is being shut down. That is where I get my notification of a leak.
Again, I'm not familiar with 3rd party leak detection tools and how they report. I usually incrementally scrutinize any changes so I know what I just changed is likely causes any reported leaks.
What was the last thing modified in the code?
|
|
|
|
|
It seems to me that I have missed the exact biuld, when it appears exactly. So, now I need some tool or information to find out, how it could be so. As you can imagine, in my oppinion there are no fresh reasons for leaks
So, does someone can help?
|
|
|
|
|
Lets reformulate the question a bit: I know the address, that leaks. I need a tool, which can tell me (after the execution of application), which line allocates at this address. Who knows such thing?
|
|
|
|
|
I haven't used VLD, but i expect that i creates a global instance of an class that checks for leaks in it's destructor.
I would also expect that there hasn't been any effort to control at what point the global object is created.
I would guess that there is a global object that is being created before VLD is initialized.
When when VLD exits all memory allocated since it was initialized has been freed, it knows nothing about memory allocated before it was initialized (so it says no leaks).
Your internal is likely the same.
So, depending on what you are calling that actually generates the leak message, you may have a leak in a global that is initialized early, or you may not have a leak at all just mis-configured leak detection code.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Thanx, but I do not think so.
1) Even without VLD I'm gettint "No leaks" and then a report about leaks from internal finder
2) I do not regulate the moment, whan VLD is created. It is kind of "p'n'p" solution: I just include it, no changes to code.
Does anyone have more ideas?
|
|
|
|
|