Results 1 to 9 of 9

Thread: The If Statement

  1. #1
    Guest

    Post

    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?

  2. #2
    Junior Member
    Join Date
    May 2000
    Posts
    24
    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

  3. #3
    Guest
    Ok i got that to work, but what do i type to terminate the program?

  4. #4
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    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.
    "People who think they know everything are a great annoyance to those of us who do."

  5. #5
    Guest
    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?

  6. #6
    New Member
    Join Date
    May 2000
    Posts
    14
    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?
    1) Assuming MSVC and a console app, look up _clearscreen() in the help files (<conio.h>).

    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.



    Shab.

    Code:
    Print WeekDayName(vbMonday)

  7. #7
    Guest
    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.

  8. #8
    New Member
    Join Date
    May 2000
    Posts
    14
    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.
    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.

    Screen clearing (CLS) provides some tips though - you may want to have a look there.
    Shab.

    Code:
    Print WeekDayName(vbMonday)

  9. #9
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width