|
Here is the problem:
scanf("%d", &numbers[limit]);
scanf("%d", &numbers[index]);
Mike Certini wrote: What I have discovered is that I have to input a \o for the program to know that it is the end of my input.
This is not true. When you enter the limit-th number the loop will end and the program will exit.
Mike Certini wrote:
Secondly, I have problems with index variable. When I loop one time or when I press enter after inputing a number, my index number advances to 8. My question is why the index does not advance to 2?
Actually it is incremented by 1 after each iteration (index++ part of your for loop) but you are indexing with wrong variable (I pointed out this problem at the start of my answer).
I hope this helps.
|
|
|
|
|
Nuri,
Oh, my....
I feel so dumb.
Thank you for your help.
|
|
|
|
|
Hi All
I create a SDI project to implement splitting window using CSplitterWnd and OnCreateClient (VC 6.0).
In MainFrm.h, two CSplitterWnd member variables are declared
public:
CMySplitter wndSplitter_horizontal;
CMySplitter wndSplitter_erect;
In MainFrm.cpp the OnCreateClienct function is as follows
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
if(wndSplitter_horizontal.CreateStatic(this,2,1)==NULL)
return FALSE;
wndSplitter_horizontal.CreateView(0,0,RUNTIME_CLASS(CMonitorTopView),CSize(50,50),pContext);
if(wndSplitter_erect.CreateStatic(&wndSplitter_horizontal,1,2,WS_CHILD|WS_VISIBLE, wndSplitter_horizontal.IdFromRowCol(1, 0))==NULL)
return FALSE;
wndSplitter_erect.CreateView(0,0,RUNTIME_CLASS(CViewRight),CSize(220,220),pContext);
wndSplitter_erect.CreateView(0,1,RUNTIME_CLASS(CViewRight),CSize(220,220),pContext);
return TRUE;
}
It works fine when a CEditView based view 'CViewRight' or 'CViewLeft' is linked to the pane with CreateView(), but failed when a CFormView based view 'CViewRight_Dlg1111' , 'CMonitorTopView' or 'CMonitorRightView' is linked to the pane, though compiling is successful.
'CViewRight_Dlg1111' is created as follows,
(1) First create a dialog resource (IDD_Dlg_1111)
(2)Invoke the 'New Class' dialog box
Class Type: MFC class
Base Class: CFormView
Dialog ID: IDD_Dlg_1111
Creating 'CMonitorTopView' and 'CMonitorRightView' follows the same way.
Also, I find that the program works fine when classes derived from CEditView, CTreeView, CView are linked to the pane .
i do not know why. Please help
I would like the program to deploy the multi-pane layout only when the user clicking a menu item, How to do this.
|
|
|
|
|
Please see the implementation of the derived constructor
in this[^] example...
(there are no dialog-related words inside)
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
|
|
|
|
|
salut a tous, j'ai une question a propos le traitement bit à bit dans le langage C :
* comment accéder au bits d'une variable quelconque et, effectivement, les modifier( les bits) tantot à 1 tantôt a 0 pour former ce qu'on appelle tableau de bits
et merci
|
|
|
|
|
You will get a better response if you ask your question in English. If English is not your first language, try one of the online translation services.
|
|
|
|
|
Please use English to describe your problem because most of us do not speak French.
(the same as above with Google translate converted to french: S'il vous plaît utiliser l'anglais pour décrire votre problème parce que la plupart d'entre nous ne parlent pas français. )
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world.
Fry: But this is HDTV. It's got better resolution than the real world <
>Nothing is free in the universe.<
|
|
|
|
|
Translating your question, I think this is what you mean:
"Hi everyone, I have a question about handling individual bits in C.
How can I access the bits of a variable and change them to either a 1 or 0."
This[^] should contain the requested info with more details on specifics in the 'See also'.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
Hi,
a 32-bit integer would have its bits numbered 0 to 31 from right to left.
their value corresponds to 1<<n where="" n="" is="" the="" bit="" number.
setting="" a="" accomplished="" with="" bitwise-or="" operator,="" symbol="" |
clearing="" bitwise-and="" &
warning:="" clearing="" done="" by="" keeping="" bits="" you="" do="" not="" want="" to="" be="" cleared,="" that="" complement="" of="" one(s)="" get="" rid="" of.
so="" following="" will="" change="" 5="" into="" 6:
<pre="">
int i=5;
int bit1=1<<1; // which is 2
int bit0=1<<0; // which is 1
i=i|bit1; // now i holds 7
i=i&~bit0; // keeping everything but bit0 yields 6
An alternative way of clearing a bit is first setting, then flipping it; flipping is handled by the bitwise-XOR, the symbol is ^.
i=5;
i=i|bit1;
i=(i|bit0)^bit0;
|
|
|
|
|
Hi All,
I am not able to Contents of File when it exceeds length of 1024.
CFile file;
if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead))
{
return false;
}
TCHAR buffer[100000];//say content is very Big
file.read(buffer,100000);
file.close();
I am not able to get the Contents into Buffer. But i am able to get the Length of the File
with int len = file.GetLength(). I am getting Junk into Buffer.
What may be the reason i am not able to get it into buffer.
Uday.
|
|
|
|
|
janaswamy uday wrote: file.read(buffer,100000);
You should always check the return value of an API function call.
See, for instance, the code sample in the _read documentation page[^].
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]
|
|
|
|
|
Try Using
CStdioFile .
Regards,
Paresh.
|
|
|
|
|
janaswamy uday wrote: if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead))
What you have posted will not even compile. That aside, this should be:
if (! file.Open("C:\\users\\rakesh\\Desktop\\myText.xml", CFile::modeRead))
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
janaswamy uday wrote:
if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead))
{
return false;
}
This means if you successfully open the file you return false instead of reading the file into your buffer.
I must get a clever new signature for 2011.
|
|
|
|
|
It may or may not be causing this issue, but the stack has limited space, and allocating 100,000 TCHARs on the stack is not a good idea.
you should instead use
LPTSTR buffer = new TCHAR[100000];
file.read();
delete []buffer;
|
|
|
|
|
Thank you very much Bruck. I will try with that.
|
|
|
|
|
I create a SDI project with VC 6.0.
I have to put
#include "testView.h"
in the file MainFrm.cpp, since I need to link testView to a splitted window pane using
wndSplitter_horizontal.CreateView(0,0,RUNTIME_CLASS(CTestView),CSize(50,50),pContext);
However, the compiler complaint with the following lines.
d:\vc_project\test\testview.h(27) : error C2143: syntax error : missing ';' before '*'
d:\vc_project\test\testview.h(27) : error C2501: 'CTestDoc' : missing storage-class or type specifiers
d:\vc_project\test\testview.h(27) : error C2501: 'GetDocument' : missing storage-class or type specifiers
The error can be replayed easily by creating a SDI project and typing in the MainFrm.cpp file
#include "TestView.h"
i have had a look online, but found no solutions.
modified on Friday, January 7, 2011 9:18 AM
|
|
|
|
|
You should include TestDoc.h as well since CTestView depends on it. In my opinion, that should have been taken care of in the TestView.h file, to make it self supporting. But sometimes compilation speed is preferred over ease-of-use.
|
|
|
|
|
Thank you for your reply.
when I create a SDI project with AppWizard,
I notice there are lines in the testView.h file
public:
CTestDoc* GetDocument();
but there is no #include "testDoc.h". The program works fine though.
However,when I simply put the line
#include "testView.h"
into the MainFrm.cpp file the error message pops up.
I think the error message is suppose to occur in the former case.
|
|
|
|
|
The reason it works fine in the first case is because in all files where testView.h is included (test.cpp and testView.cpp in a standard project), testDoc.h is included before testView.h.
#include "testDoc.h"
#include "testView.h"
So the advice to include testDoc.h first, is correct.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
|
i want to use bitmap image on button of media player usig active x contol
in mfc application
|
|
|
|
|
|
Hi,
This question is more from the point of view of Threads than C/C++. I have a destroy() function which waits on a thread (lets say _monitor) through PR_JoinThread(). The problem is that the _monitor thread has various time-oriented operations such as read()/write() socket calls so it takes time to finish off before exiting. Hence the destroy() function due to this PR_JoinThread which waits on the _monitor to exit is hanging the process (my product creates around 80-90 such threads) for around 6-7 minutes. Can anyone tell me the way to avoid such a situation? Is there any way other than using PR_JoinThread?
Thanks.
|
|
|
|
|
I don't know the api you are using (PR_JoinThread, google gives me something like NSPR API, whatever that might be) but generally if you don't want your "waiter thread" to block, you could either poll the other thread's state time to time, going on with your regular business in the meantime, or have somekind of messaging implementing with which the thread you would be waiting for can signal towards the waiter that it has finished processing, e.g. if you are working with VC++ you could use PostThreadMessage to send a message towards your GUI thread. Could this help?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world.
Fry: But this is HDTV. It's got better resolution than the real world <
>Nothing is free in the universe.<
|
|
|
|