|
Forgive me if I may have sounded crude. I have researched google dreamincode codeguru among other search engines and did not find my answer /cry, sorry im just frustrated. This is role of my program. Think of it as a uname/pword program which leads to a basic encryption or start of it:
--role--
Please input a 5 digit number: 78265
Your input was 78265, is this correct? y
--role--
Now, knowing user input was a 5 digit number, that should then be broken down into and array of integers:
78265 Each element of the 5 digit number would be placed into an array after user input ie: 7,8,2,6,5
|
|
|
|
|
Much clearer. How about something like:
string strNumber = "78265";
int nDigits[5];
nDigits[0] = strNumber[0] - '0';
nDigits[1] = strNumber[1] - '0';
nDigits[2] = strNumber[2] - '0';
nDigits[3] = strNumber[3] - '0';
nDigits[4] = strNumber[4] - '0';
"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
|
|
|
|
|
strNumber cannot be declared in the program. The strNumber has to ask for users input, because the number could be anything that user specifies. smell my drift? . There has to be a way to store the users input '12345' in an array after they type it in.
-- modified at 15:09 Tuesday 18th September, 2007
Here is antoher extended role
--role
Please type in a five digit number: 79135 //Ask for user input
The number you typed was'79135' is this correct? y //Is input correct y/n
The first number '7' from 79135 will be stored in aArray[0]. //store 7 in array0
The second number '9' from 79135 will be stored in aArray[1]. //store 9 in array0
The third number '1' from 79135 will be stored in aArray[2]. //store 1 in array0
The fourth number '3' from 79135 will be stored in aArray[3]. //store 3 in array0
The fifth number '5' from 79135 will be stored in aArray[4]. //store 5 in array0
Each element of the 5 digit number from user input have been stored individually in the array[5]
--role--
|
|
|
|
|
Herboren wrote: strNumber cannot be declared in the program. The strNumber has to ask for users input, because the number could be anything that user specifies. smell my drift?
Yes, and what I showed was merely an example. I'm not in the position of providing all of the cin /cout statements that you require. Even new developers know that string strNumber = "79135" can be turned into a user input-able statement with but one line of code. How a value gets assigned to a variable, either via the keyboard or as a string literal, is irrelevant.
Herboren wrote: The first number '7' from 79135 will be stored in aArray[0]. //store 7 in array0
The second number '9' from 79135 will be stored in aArray[1]. //store 9 in array0
The third number '1' from 79135 will be stored in aArray[2]. //store 1 in array0
The fourth number '3' from 79135 will be stored in aArray[3]. //store 3 in array0
The fifth number '5' from 79135 will be stored in aArray[4]. //store 5 in array0
Why would you want all five digits stored in array0 ? Furthermore, what is array0 ?
"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
|
|
|
|
|
it was supposed to say
//store in aArray[0] //example
//store in aArray[1] //example
//store in aArray[2] //example
//store in aArray[3] //example
//store in aArray[4] //example
this was only an example, this has nothing to do with my code this was just a role just so you could better understand what I was trying to say.
<quote>Yes, and what I showed was merely an example. I'm not in the position of providing all of the cin/cout statements that you require.
I know it was an exmaple and im not asking you to tell what the cin and cout is. I know I can grab sets of digits as a string, I know basically everything you just told me. I dont know any other basic way to put it, i have role played it for you twice now and you still dont seem to understand what im saying. Reverting back to the 2nd question I asked yesterday, The problem I am having is storing each e-l-e-m-e-n-t of the "string" into an a-r-r-a-y.
|
|
|
|
|
Herboren wrote: it was supposed to say
//store in aArray[0] //example
//store in aArray[1] //example
//store in aArray[2] //example
//store in aArray[3] //example
//store in aArray[4] //example
this was only an example,
And is exactly what I showed you in my code snippet.
Herboren wrote: The problem I am having is storing each e-l-e-m-e-n-t of the "string" into an a-r-r-a-y.
I've showed you how to do this twice, using two different approaches. What are you not understanding?
"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
|
|
|
|
|
Holy shat dude it worked. you are the bomb digitty. Heh I knew I could get user input by doing cin >> string; which normally a string is a chain of characters I guess I should say symbols and I thought the string had to be converted to integers first before storing them into and array. yeah I know char's can be stored in arrays to but I had planned on adding different numerals to each int stored in the array, so i assumed i wouldnt be able to add numberals to char's stored in the array, thats like saying 1 + a or 2 + b which then would result in an error of some sort. But it worked perfectly all thanks to you. sorry if i may have sounded a little edgy, it was out of my perspective which is why i was not understanding.
Okay so the part I dont understand is the "- '0'" when converting the str to the array. Awesome im glad we completed that. Now here is another doosy. I need to create an array based on the amount of symbols in the str, so instead of pre.creating the 'aArray[5]' im using the strlen(str.c_str()) to count the number of symbols in the str from the users input. this is my code so far:
<br />
<br />
#include "stdafx.h"<br />
#include <string><br />
#include <iostream><br />
#include <conio.h><br />
using namespace std;<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
string str;<br />
int aArray[5];<br />
int n;<br />
<br />
cout << "Input a 5-digit number: "; <br />
<br />
<br />
cin >> str;<br />
<br />
aArray[0] = str[0] - '0';<br />
aArray[1] = str[1] - '0';<br />
aArray[2] = str[2] - '0';<br />
aArray[3] = str[3] - '0';<br />
aArray[4] = str[4] - '0';<br />
<br />
cout << "The length of " << str << " is: " << strlen( str.c_str()) << endl;<br />
<br />
_getch(); <br />
return 0;<br />
}<br />
<br />
<br />
-- modified at 17:54 Tuesday 18th September, 2007
|
|
|
|
|
Herboren wrote: cout << "The length of " << str << " is: " << strlen( str.c_str()) << endl;
Since you are using a string object:
cout << "The length of " << str << " is: " << str.length() << endl; Herboren wrote: I need to create an array based on the amount of symbols in the str, so instead of pre.creating the 'aArray[5]' im using the strlen(str.c_str()) to count the number of symbols in the str from the users input.
int *nArray = new int[what_number_goes_here?];
...
delete [] nArray;
"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
|
|
|
|
|
hi
can anybody help me regarding how to write a vc++ code for opening,closing and saving an image???It would be great if anyone is having code for this..
Thanks & Regards,
Ravan
|
|
|
|
|
|
You do realize there are MANY image file formats, right?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
And see CXImage class on the codeproject.
|
|
|
|
|
Excuse me,dear sir.Recenntly I am building a MDI project with several views only one document.There are some views from cview,some from CScrollview,and others from CformView.We have many CButton controls on the views derived from CFromview.Now I want use those button controls to switch those views.namely every button is corresponding with one view.How to do this ??
Thank in advance
lkx
|
|
|
|
|
That is a tall order, not really that simple.
Take a look at this article http://www.codeproject.com/dialog/visualfx.asp.
The author essentially puts all views in a splitter.
Let me know if I can be of any help after you read it.
Vaclav
PS English is not my native language however in an informal enviroment like this group is you do not need to start "excuse me..."
I can speak only for myself but this is a very friendly bunch.
Just say "Hi" in future.
Cheers
|
|
|
|
|
Hey,
I have realized you are the one I tried to help with the dinamically creation of views and its relationships. Did you get it?
Greetings.
--------
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?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
First of all....
Several Views = Always the same number of views??? OR
Several Views = Random numbers of views (as much as needed)????
The views are created all in once and then want to change the active? or the views are created one per one (i.e. clicking a button "create" or doubleclicking in an element?)
You want to have only one CFormView with a button for every other view? or a relation of buttons in every window that allow you to switch to every other view?
If the view is closed, you want to create it? or you can only go to that view when it is opened?
It's possible and relative easy (depending on your answers may be more complicated)
Greetings.
--------
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?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Hi,
nice to hear from you.
Well I am currently developing an application which has three documents and they all have pretty much same "static" views. Presently I do not need dynamic / new views and have put such creation on back burner. But I do remeber your solution and have a copy of it in my project - thanks.
I do like mentioned visual framework but I keep running into problems with it. Right now I have changed the way the documents are manipulated ( document alters the text file) and one of the views has a rich text control attached to display the text file.
And it asserts on creation of the view... It worked fine when the file got procesed in the view itself. So I am debugging,
Cheers
Vaclav
|
|
|
|
|
I faced out with such assertions during my project. It can be that you are trying to initialize the values of the control in the constructor of the view. Does will crash because the view is being created but it is not yet. So the controls that needs relationships with the frame which contains them, doesn't have the handlers in this moment and an assertion comes.
I solved it creating/initializating/charging datas for the controls in the OnInitialUpdate ();
maybe works for u too
Greetings.
--------
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?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
I'm learning C++/MFC (Visual C 3.0). I've successfully written a MFC program that has menus, and one of the menus brings up a dialog box.
When the 'OK' is selected on the dialog box, I want the non-trivial application code to run. It takes 20+seconds. Then another dialog box is needed.
How do I call/cause the application code to run, and when it has completed, how do I bring up the second dialog box?
===========================================================
the first Dialog box code snippet where I can capture the 'OK':
nRet=dlg.DoModal();
// Handle the return value from DoModal
switch ( nRet )
{
case IDOK:
// Do something
Thanks in advance
Dan
|
|
|
|
|
daniel33433 wrote: ...when it has completed, how do I bring up the second dialog box?
Since you are using a modal dialog box, DoModal() does not return until the dialog has been dismissed.
"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
|
|
|
|
|
For info on starting another process, see here[^]
Once you get the other process running, if you want to wait for it to finish,
you're getting out of newbie territory.
If you want the spawning app to remain responsive, it needs to process window
messages while waiting for the spawned app to complete. There's lots of ways
to do this.
Here's an example of one method for you to study.
This example
1) creates another process (I used Notepad as an example)
2) disables the main window of the calling app so the user can't do anything there
(note that this example was tested from the main window class. You may need to
enable/disable your app's main window a little differently, depending on where this code
is used)
3) enters a modal loop to wait for the spawned process to terminate. To keep
the calling app responsive in the meantime, queued window messages are dispatched.
4) enables the main window of the calling app so the user can continue
*Edit* Replace those stupid smilies with capital 'P's LOL
nRet=dlg.DoModal();
switch ( nRet )
{
case IDOK:
{
STARTUPINFO StartupInfo;
memset(&StartupInfo, 0, sizeof(STARTUPINFO));
StartupInfo.cb = sizeof(STARTUPINFO);
StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow = SW_SHOWDEFAULT;
PROCESS_INFORMATION ProcessInfo;
if (::CreateProcess(_T("C:\\WINDOWS\\notepad.exe"),
NULL,
0,
0,
FALSE,
NORMAL_PRIORITY_CLASS,
0,
0,
&StartupInfo,
&;ProcessInfo
))
{
EnableWindow(FALSE);
while (true)
{
DWORD dwWaitRet = ::MsgWaitForMultipleObjects(1, &;ProcessInfo.hProcess, FALSE, INFINITE, QS_ALLEVENTS);
if (WAIT_OBJECT_0 == dwWaitRet)
{
break;
}
else if (WAIT_OBJECT_0 + 1 == dwWaitRet)
{
MSG msg;
while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
AfxGetApp()->;PumpMessage();
}
}
::CloseHandle(ProcessInfo.hProcess);
::CloseHandle(ProcessInfo.hThread);
EnableWindow(TRUE);
}
}
} I hope this gives you some ideas to work with. There's many ways to do this.
This example is relatively simple and doesn't involve multiple threads.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi -
I'd like to create online backups of my Visual Studio directories. I work from a location with a reeeeeaaaallllllyyyyy sllllloooowwww connection, so I was thinking of creating as minimal backups as possible. Has anyone solved this problem?
I was thinking that I only need the .vcproj, the .rc, the source code (.cc and .h) to be able to completely recreate the project.
Am I on the right track here?
Thanks!
|
|
|
|
|
I back up every couple of hours or after a major code problem gets solved/overcome.
In order to make it all fit in a reasonable space, I just delete the .ncb file, release folder , and debug folders. Those seem to be the biggest users of disk space (for medium to large projects at least) IMO.
|
|
|
|
|
ok, that fits the bill perfectly - thanks!
|
|
|
|
|
Hello,
I have UDP app that works fine, except on Windows Vista.
The error is WSAEINVAL (10022) on sendto function, and the package did not send
Anyone know this problem?
Thanks,
Cris.
|
|
|
|