Re: conditional if..else
Re: conditional if..else
- Subject: Re: conditional if..else
- From: Boyd Collier <email@hidden>
- Date: Tue, 17 Jul 2007 11:20:26 -0700
Frank,
You need to brush up your understanding of how c deals with arrays of
chars. Here's a good place to start:
http://publications.gbdirect.co.uk/c_book/chapter5/
character_handling.html
Boyd
On Jul 17, 2007, at 11:03 AM, email@hidden wrote:
Message: 14
Date: Tue, 17 Jul 2007 14:00:10 -0400
From: Frank Murray <email@hidden>
Subject: conditional if..else
To: Xcode-Users <email@hidden>
Message-ID: <email@hidden>
Content-Type: text/plain; charset="us-ascii"
Hello,
This is a new post, and I am relatively new to the XCode IDE.
Listed below is a
snippet of code, using string (char) constants along with if...else
statements. The code
speaks for itself, but obviously does not work the intended way.
Meaning, no matter if you enter "Celcius" or "Fahrenheit", the
conditional always defaults
to "neither." I'm guessing the code if <some condition> == <some
string or char statement>
is not being equated or compiled properly, so any info is
appreciated. Thanks.
fjm
#include <stdio.h>
int main (int argc, const char * argv[]) {
char scale[12];
printf ("Enter the temperature scale you're coming from, either
Celcius or fahrenheit.\n");
scanf ("%s", &scale);
printf ("%s\n", scale);
if (scale == "Celcius")
{
printf ("You're in the Celcius scale.\n");
}
else if (scale == "Fahrenheit")
{
printf ("You're in the Fahrenheit scale.\n");
}
else
printf ("Looks like you're in neither.\n");
return 0;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden