|
-
Apr 7th, 2002, 01:33 AM
#1
Weird...
PHP Code:
//---------------------------------------------------------------------------
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
char cChar[1];
start:
clrscr();
printf("How ya doin?\nI'm doin fine.\n");
printf("Press Q or q to exit: ");
gets(cChar);
goto end;
end:
if(*cChar == 'Q' || *cChar == 'q')
{
return 0;
}
else
{
MessageBox(NULL, "You Pressed " + *cChar, "Test", MB_OK);
goto start;
}
}
//---------------------------------------------------------------------------
I'm using this, but when I run it, and press a key other than Q or q, it gives me something like $qrii instead of like "You Pressed A", or something. Can someone tell me what I'm doing wrong? As you can see, I'm a complete newb, so any help is greatly appreciated.
-
Apr 7th, 2002, 03:16 AM
#2
read up strings in the tutorial/faq at the top of the page. You can't use normal operators to manipulate pure strings.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 7th, 2002, 08:43 PM
#3
Dont use labels and gotos. Your code should look like this:
Code:
int main(...)
{
char cChar[2];
char buff[64];
while(true) // infinite loop
{
clrscr();
printf("How ya doin?\nI'm doin fine.\n");
printf("Press Q or q to exit: ");
gets(cChar);
if(*cChar == 'Q' || *cChar == 'q')
{
return 0; // break the loop, and quit
}
else
{
sprintf(buff, "You Pressed %s", cChar);
MessageBox(NULL, buff, "Test", MB_OK);
}
}
}
You might have to swap the literal "You Pressed %s" with buff in the call to sprintf, because I dont remember which comes first.
Z.
[eidt]
fixed the code sample
-
Apr 8th, 2002, 11:55 AM
#4
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|