|
DanYELL wrote: if (a == 1) dwID = IDC_EDIT1;
if (a == 2) dwID = IDC_EDIT2;
if (a == 3) dwID = IDC_EDIT3;
Can you show how 'a' is passed. Possibly it is not going through any of above condition and 'dwID' is having garbage value.
DanYELL wrote: CWnd *pWndChild = pView->GetDlgItem( (UINT)dwID);
and this statement is initializing pWndChild with NULL.
|
|
|
|
|
Hello, perhaps someone can answer this for me without me having to display my entire program.
I am having issues with one of my cin statements getting read in by a user's keyboard input. I am using the debugger in Visual C++ and it appears as though the compiler is skipping this cin statement and moving to the next cout statement. This seems to happen when the program is moving from one function call to another in main(). I found a fix to this by adding 2 consecutive cin statements but I know this is not the correct way to program. Has anyone had a similar experience. If so, how did you handle it.
Thanks,
HRW.
-- modified at 12:56 Monday 24th July, 2006
|
|
|
|
|
How are we expected to offer any reasonable solution without seeing the problematic code? We don't need to see all of it, just the relevant snippet.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Here is a condensed version. There are 2 functions below. Function 1 gets called before function 2. The problem appears in function 2 where I had to enter 2 cin statements. I hope it's readable as the cut and paste did not translate well.
void add_number_of_subunits (int& data)
{
char buff[1024];
unsigned int value;
int charsRead;
bool validEntry = false;
while (!validEntry)
{
cout << endl;
cout << "Please enter number of subunits: ";
cin >> buff;
if (sscanf(buff,"%u%n", &value,&charsRead)==1 && value >=1 && value <= 12)
validEntry = true;
}
data = value;
}
void add_node_at_end(data& item, int& increment)
{
char buffer[501] = {0};
cout << "Please enter the length of the protein sequence for Subunit " << increment << "> ";
cin >> buffer;
cin.getline(buffer, 500, '\n');
item.Length = buffer;
memset(buffer, 0, 501);
cout << "Please enter the protein sequence for Subunit " << increment << "> ";
cin.getline(buffer, 500, '\n');
while (buffer == "\n")
{
cout << "A sequence is required!" << endl;
cout << "Please enter a sequence." << endl;
cin.getline(buffer, 500, '\n');
}
item.Sequence = buffer;
memset(buffer, 0, 501);
item.number = item.Sequence.size();
cout << "Enter brief status on the presence of a modified N_Terminal: ";
cin.getline(buffer, 500, '\n');
item.N_Terminal = buffer;
memset(buffer, 0, 501);
cout << "Enter brief status on the presence of a modified C_Terminal: ";
cin.getline(buffer, 500, '\n');
item.C_Terminal = buffer;
memset(buffer, 0, 501);
g_DataList.push_back(item);
cout << endl;
increment++;
}
-- modified at 13:08 Monday 24th July, 2006
|
|
|
|
|
Harold_Wishes wrote: cin >> buffer; // I had to enter 2 cin statements since the compiler for whatever reason
cin.getline(buffer, 500, '\n'); // was not accepting one of them.
What compiler error were you receiving (when only one was present)?
Harold_Wishes wrote: while (buffer == "\n")
What are you hoping to accomplish with this?
If you are going to create a C++ program, quit messing around with char[] variables. Use string instead, especially since you are populating them with cin .
|
|
|
|
|
The compiler is not giving me an error per se. It's building the executable. But, when I run the executable, I am prompted to enter data in sequence with a series of multiple cout prompts and cin inputs. I have no problems when I am doing this in the first function call. But when main() makes a call to function 2 after function 1 terminates, the very first cin input in function 2 seems to get skipped (at least that is what the debugger is showing me). It does not recognize it). The debugger moves right to the next cout prompt.
If I remember correctly, I took this out of functions and slapped it out all in main() without any troubles.
|
|
|
|
|
Sans the comments, and extraneous code, this should get you real close:
void add_number_of_subunits (int& data)
{
string buff;
do
{
cout << endl;
cout << "Please enter number of subunits: ";
cin >> buff;
} while (atoi(buff.c_str()) < 1 || atoi(buff.c_str()) > 12);
data = atoi(buff.c_str());
}
void add_node_at_end(_data& item, int& increment)
{
string buffer;
cout << "Please enter the length of the protein sequence for Subunit " << increment << "> ";
cin >> buffer;
item.Length = buffer;
cout << "Please enter the protein sequence for Subunit " << increment << "> ";
cin >> buffer;
item.Sequence = buffer;
item.number = item.Sequence.size();
cout << "Enter brief status on the presence of a modified N_Terminal: ";
cin >> buffer;
item.N_Terminal = buffer;
cout << "Enter brief status on the presence of a modified C_Terminal: ";
cin >> buffer;
item.C_Terminal = buffer;
cout << endl;
increment++;
}
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
This code looks vaguely familiar ... someone else was asking about a similar problem a couple weeks ago.
Anyway, the problem you are having is that when using cin, it ignores whitespace by default (that is, it sees it, but leaves it in the buffer). This is generally a problem only when reading in strings, but can happen in certain circumstances when reading other datatypes. Basically, this is what happens:
Lets say that the following string is in the read buffer for cin: MyString\n
cin will read "MyString" into the buffer and leave the \n on the read buffer.
Now, the next cin call will see the \n and assume an empty string.
An easy way to fix the problem would be to change:
DavidCrow wrote: void add_number_of_subunits (int& data)
{
string buff;
do
{
cout << endl;
cout << "Please enter number of subunits: ";
cin >> buff;
} while (atoi(buff.c_str()) < 1 || atoi(buff.c_str()) > 12);
data = atoi(buff.c_str());
}
to be this instead:
void add_number_of_subunits (int& data)
{
int check = 0;
do
{
cout << endl;
cout << "Please enter number of subunits: ";
cin >> check;
} while (check < 1 || check > 12);
data = check;
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: This code looks vaguely familiar ... someone else was asking about a similar problem a couple weeks ago.
Same person. Still using sscanf() for validation, even though you provided him an alternative!
Zac Howland wrote: int check = 0;
...
cin >> check;
I thought about this (i.e., using an int ), but since he was storing the input string for later processing, I left it as a string .
|
|
|
|
|
DavidCrow wrote: Same person. Still using sscanf() for validation, even though you provided him an alternative!
So it is. In C++, there are very few cases where using sscanf does not constitude a flaw in your implementation. This is not one of them.
DavidCrow wrote: I thought about this (i.e., using an int), but since he was storing the input string for later processing, I left it as a string.
Since he needs it to set the iterations for a loop, it is easier (and more efficient) to read it as an int and to then call itoa or sprintf or use streambufs to store it for whatever purpose.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
To Zac:
My last response was just made to the other member (David_Crow) who provided some feedback, but I understand your point with the string datatype and will test this out.
Thanks
HRW.
-- modified at 15:29 Monday 24th July, 2006
|
|
|
|
|
Although this did solve my original issue, it has caused 2 old problems to crop up again.
1) I want the user to be able to bypass keyboard entrys when they hit ENTER if they choose to skip a question. Now when I hit ENTER, the program will not let me go to the next cout prompt. It is waiting for something other than "\n" character. I believe this is why I used my getline implementation.
2)Also, if I type in something like "new terminal", such entrys delimited by a space seem to cause the next cin input to read in the second string. But I need to test the output some more with this second issue since I'm getting other strange results.
|
|
|
|
|
Harold_Wishes wrote: 1) I want the user to be able to bypass keyboard entrys when they hit ENTER if they choose to skip a question. Now when I hit ENTER, the program will not let me go to the next cout prompt. It is waiting for something other than "\n" character. I believe this is why I used my getline implementation.
That sounds familiar now. I don't agree with this behavior, but if you trully want it, the way to go about it is to do 2 consequetive getline calls (the first will get your data, the second will get you passed the '\n').
Harold_Wishes wrote: 2)Also, if I type in something like "new terminal", such entrys delimited by a space seem to cause the next cin input to read in the second string. But I need to test the output some more with this second issue since I'm getting other strange results.
That is the desired implementation for cin. You can override it, but generally, it is easier to just use getline if you need to get a string with spaces in it.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Regarding my first question, you're suggesting something like below:
char buffer[501] = {0};
cout << "Please enter the length of the protein sequence for Subunit;
cin.getline(buffer, 500, '\n');
cin.getline(buffer, 500, '\n');
I probably need to modify the above some since both getline functions are doing the same thing
-- modified at 16:21 Monday 24th July, 2006
|
|
|
|
|
No, buffer would get overwritten the second time.
char buffer[501] = {0};
char buffer1[501] = {0};
<br />
cout << "Please enter the length of the protein sequence for Subunit;<br />
cin.getline(buffer, 500, '\n'); <br />
cin.getline(buffer1, 500, '\n');
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
For some reason, this seems to work although I do not know why it should. "cin" does not account for spaces. I added strings with spaces and no troubles much to my surprise
char buffer[501] = {0};
cout << "Please enter the length of the protein sequence;
cin >> buffer;
cin.getline(buffer, 500, '\n');
-- modified at 17:56 Monday 24th July, 2006
UPDATE: I see from the output 2 getlines are needed.
|
|
|
|
|
Why are you surpised that would work? That is pretty much what one of the examples I posted does. The reason it works is that the >> operator for cin will read until it hits whitespace, but not read the whitespace. getline reads until it gets to the number of characters you specificed, or the character you requested and does read it in.
You really should look into the use case for "skipping" inputs in a console application. I can't think of any time where I would want the user to be able to hit enter and skip entering data. Now, entering a specific value to state they want to skip it, that is a different story ...
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Harold_Wishes wrote: 1) I want the user to be able to bypass keyboard entrys when they hit ENTER if they choose to skip a question. Now when I hit ENTER, the program will not let me go to the next cout prompt. It is waiting for something other than "\n" character. I believe this is why I used my getline implementation.
So what about something like:
do
{
cin.clear();
cin.ignore(100, '\n');
cout << "Please enter number of subunits: ";
cin >> data;
} while (! cin && (data < 1 || data > 12));
Harold_Wishes wrote: 2)Also, if I type in something like "new terminal", such entrys delimited by a space seem to cause the next cin input to read in the second string. But I need to test the output some more with this second issue since I'm getting other strange results.
Then you would indeed need to use:
string buffer;
cout << "Please enter the length of the protein sequence for Subunit " << increment << "> ";
getline(cin, buffer);
|
|
|
|
|
in my Apllication i have to form first form i can display like
CDialog form1(IDD_FORM1)
form1.DoModal();
when i Try to do same thing with DoModal
it is nit working . how can i do my application
janan
|
|
|
|
|
ningthemcha wrote: when i Try to do same thing with DoModal
it is nit working .
This makes no sense. You are using DoModal() . What's the problem?
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Visual C++ 6.0 standard edition had an executable in the IDE directory that was basically the Microsoft Developement Environment IDE (mse.exe) and allowed for editing of HTML files with a very useful "script outline" window.
I'm in search of the equivalent "script outline" window in VC++ 2003 Standard Edition but I'm fearing it has been stripped in this version. Does anybody know of a way to get that paricular functionality directly or indirectly in VC++ 2003 Standard Edition?
|
|
|
|
|
Scratch that question. I found the button right after I posted...
|
|
|
|
|
Hi !
Does anybody know where I can download the Windows NT 4.0 Driver Development Kit ?
Many thanks in advance !
|
|
|
|
|
and how many forums do you plan to ask like that ?
have you searched the Microsoft website[^] ?
|
|
|
|
|
Hello All
I am trying to load a DLL dynamically using LoadLibrary (). It works fine with Windows
2000 Professional. But when i am trying to load it in XP or 2003 Server I get error "The specified module could not be found" Error.
DLL is present in the path where EXE is present. (C:\Program Files\Test Application\MyDll.dll").
When loading the DLL i am specifing full path as parameter.
I placed the DLL path to C:\ and in System32 directory and changed the path still I get the error.
DLL is basic C DLL. Unfortunately I did not get lib file along with DLL so i have load that DLL
dynamically only.
For MSDN i found that
Windows Server 2003, Windows XP SP1: The default value of HKLM\System\CurrentControlSet\Control\Session Manager\SafeDllSearchMode is 1 (current directory is searched after the system and Windows directories).
But after searching Windows Directory it has to come to current directory to find DLL. But it fails
Please tell me any idea why this strange behaviour with Windows XP and 2003 Server!!!!.
Thanks for your Time
Ravi
|
|
|
|
|