Thread: Strings and if

  1. #1
    Registered User
    Join Date
    Nov 2009

    Strings and if

    Instead of trying to explain what I am attempting to do I'll just post the code:
    int main() {
    	char answer [50];
    	char ans1;
    	printf("Work out?\n");
    	scanf("%s", answer);
    	if (answer=='Pressure') {
    	else {
    As you would know that is a big bowl of fail :P been trolling around the internet trying to find out how to go about if statements and strings and cant find anything (apart from with c++ and that just confuses me even more).

    Would be grateful if anyone could spare some in-sight

  2. #2
    Join Date
    Oct 2007
    Inside my computer
    Use strcmp and compare to 0.
    Also, single quotes means one character, and double quotes means a string.
    So, 'a' = a char, "a" = a string (char*).

    Also, read up on Scanf woes.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed