|
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.
|
|
|
|
|
Tough to guess without knowing the code
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Cris wrote: The error is WSAEINVAL (10022) on sendto function...
WSAEINVAL = "An unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled."
"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
|
|
|
|
|
This is my code:
<br />
SOCKET m_maSocketOut;<br />
struct sockaddr_in m_SockAddrOut;<br />
unsigned long m_lInet;<br />
.<br />
.<br />
<br />
void init(CString strServer)<br />
{<br />
unsigned long lInet=0;<br />
<br />
memset(&m_SockAddrOut, 0, sizeof(m_SockAddrOut));<br />
<br />
m_maSocketOut = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); <br />
m_SockAddrOut.sin_family = AF_INET;<br />
m_SockAddrOut.sin_port = htons(port);<br />
<br />
struct hostent FAR* hp = gethostbyname((char FAR *) (const char *) strServer);<br />
<br />
if (hp == NULL)<br />
{<br />
lInet = inet_addr((const char * ) strServer); <br />
if (lInet != INADDR_NONE) <br />
{<br />
validIP = TRUE; <br />
byAddress = TRUE; <br />
}<br />
}<br />
else<br />
validIP = TRUE;<br />
<br />
if (validIP)<br />
{<br />
if (byAddress)<br />
{<br />
m_SockAddrOut.sin_addr.s_addr = lInet;<br />
m_lInet = lInet;<br />
}<br />
else<br />
{<br />
m_SockAddrOut.sin_addr.s_addr = *((unsigned long far *) hp->h_addr);<br />
m_lInet = *((unsigned long far *) hp->h_addr);<br />
}<br />
<br />
if (m_maSocketOut != NULL)<br />
{<br />
bind(m_maSocketOut, (SOCKADDR*)& m_SockAddrOut, sizeof(m_SockAddrOut));<br />
WSAAsyncSelect(m_maSocketOut, hWnd, WM_EXTERNA, FD_READ | FD_CLOSE);<br />
}<br />
}<br />
}<br />
<br />
void sendData(char szData[], int len)<br />
{<br />
int result = sendto(m_maSocketOut, (char FAR *) &szData, len, <br />
NULL, (PSOCKADDR) &m_SockAddrOut, sizeof(m_SockAddrOut));<br />
m_SockAddrOut.sin_addr.s_addr = INADDR_ANY;<br />
<br />
if (result < 0)<br />
{<br />
int erroCode = WSAGetLastError();<br />
}<br />
}<br />
Important: This error code is only on Windows Vista, but not all instalations . I don't know which the exat situation, but I observed in Business and Ultimate version.
Any idea?
|
|
|
|
|
Could it be a UAC thing?
"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
|
|
|
|
|
No, the UAC configuration is not enabled.
|
|
|
|