• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
conditional if..else
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

conditional if..else


  • Subject: conditional if..else
  • From: Frank Murray <email@hidden>
  • Date: Tue, 17 Jul 2007 14:00:10 -0400

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

  • Follow-Ups:
    • Re: conditional if..else
      • From: Tommy Nordgren <email@hidden>
    • Re: conditional if..else
      • From: "Clark Cox" <email@hidden>
    • Re: conditional if..else
      • From: Charlton Wilbur <email@hidden>
  • Prev by Date: Re: More on embedding frameworks
  • Next by Date: Re: Odd Console messages after kernel panic
  • Previous by thread: How do I turn on coloring in the Memory Browser?
  • Next by thread: Re: conditional if..else
  • Index(es):
    • Date
    • Thread