Ok, im using C and i cant get this code to work...
int check;
scanf("%s", &check);
if(check == 'hi')
printf("Hello\n");
The problem is when I type "hi", it wont print "Hello".
Any idea?
Printable View
Ok, im using C and i cant get this code to work...
int check;
scanf("%s", &check);
if(check == 'hi')
printf("Hello\n");
The problem is when I type "hi", it wont print "Hello".
Any idea?
I think you need to use double quotes around the "hi" rather than single quotes. If I remember right, single quotes are used for char variables and double quotes are used for strings. But it's been a while, so forgive me if I am wrong.
-CD
Ok i got that to work, but what do i type to terminate the program?
You mean in the code itself? Return 0 from main to indicate successful termination. Otherwise return 1.
Or if you include "STDLIB.H" you can call the exit function which is: exit(status)
where status is 0 for sucess or 1 for error.
Ok thanks i got the exit thing to work. Now i got to more questions.
1. How do i clear the screen?
2. Is there a place (like a web site or something? ) to look up the functions in the header files and see what they do?
1) Assuming MSVC and a console app, look up _clearscreen() in the help files (<conio.h>).Quote:
Originally posted by ChimpFace9000
Ok thanks i got the exit thing to work. Now i got to more questions.
1. How do i clear the screen?
2. Is there a place (like a web site or something? ) to look up the functions in the header files and see what they do?
2) Do you have the help files? :) Failing that a web search for one of the functions will no-doubt get you a few pages with some sorta defn for them.
Ok, i found it but couldnt get it to work. This is the header file i included <conio.h> and then i typed clearscreen() to clear the screen, but it didnt work.
Hmm - my bad for not actually checking it. Having looked it up on the web, it appears there's no easy (nor standard) way of doing it.Quote:
Originally posted by ChimpFace9000
Ok, i found it but couldnt get it to work. This is the header file i included <conio.h> and then i typed clearscreen() to clear the screen, but it didnt work.
Screen clearing (CLS) provides some tips though - you may want to have a look there.
if your using the Turbo C buy borland than to clear the screen all you have to do is, but not allways, include the <conio.h> and simply call the function clrscr();
Jeremy :)