Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6887137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:50:52+00:00 2026-05-27T05:50:52+00:00

This might seem like a very simple question, but I am struggling with it.

  • 0

This might seem like a very simple question, but I am struggling with it. I have been writing iPhone apps with Objective C for a few months now, but decided to learn C Programming to give myself a better grounding.

In Objective-C if I had a UILabel called ‘label1’ which contained some text, and I wanted to run some instructions based on that text then it might be something like;

if (label1.text == @"Hello, World!")
{
NSLog(@"This statement is true");
}
else {
NSLog(@"Uh Oh, an error has occurred");
}

I have written a VERY simple C Program I have written which uses printf() to ask for some input then uses scanf() to accept some input from the user, so something like this;

int main()
{
    char[3] decision;

    Printf("Hi, welcome to the introduction program.  Are you ready to answer some questions? (Answer yes or no)");
    scanf("%s", &decision);
}

What I wanted to do is apply an if statement to say if the user entered yes then continue with more questions, else print out a line of text saying thanks.

After using the scanf() function I am capturing the users input and assigning it to the variable ‘decision’ so that should now equal yes or no. So I assumed I could do something like this;

if (decision == yes)
{
     printf("Ok, let's continue with the questions");
}
else 
{
     printf("Ok, thank you for your time.  Have a nice day.");
}

That brings up an error of “use of undeclared identifier yes”. I have also tried;

if (decision == "yes")

Which brings up “result of comparison against a string literal is unspecified”

I have tried seeing if it works by counting the number of characters so have put;

if (decision > 3)

But get “Ordered comparison between pointer and integer ‘Char and int'”

And I have also tried this to check the size of the variable, if it is greater than 2 characters it must be a yes;

if (sizeof (decision > 2))

I appreciate this is probably something simple or trivial I am overlooking but any help would be great, thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:50:53+00:00Added an answer on May 27, 2026 at 5:50 am

    Daniel Haviv’s answer told you what you should do. I wanted to explain why the things you tried didn’t work:

    if (decision == yes)
    

    There is no identifier ‘yes’, so this isn’t legal.

    if (decision == "yes")
    

    Here, “yes” is a string literal which evaluates to a pointer to its first character. This compares ‘decision’ to a pointer for equivalence. If it were legal, it would be true if they both pointed to the same place, which is not what you want. In fact, if you do this:

    if ("yes" == "yes")
    

    The behavior is undefined. They will both point to the same place if the implementation collapses identical string literals to the same memory location, which it may or may not do. So that’s definitely not what you want.

    if (sizeof (decision > 2))
    

    I assume you meant:

    if( sizeof(decision) > 2 )
    

    The ‘sizeof’ operator evaluates at compile time, not run time. And it’s independent of what’s stored. The sizeof decision is 3 because you defined it to hold three characters. So this doesn’t test anything useful.

    As mentioned in the other answer, C has the ‘strcmp’ operator to compare two strings. You could also write your own code to compare them character by character if you wanted to. C++ has much better ways to do this, including string classes.

    Here’s an example of how you might do that:

    int StringCompare(const char *s1, const char *s2)
    { // returns 0 if the strings are equivalent, 1 if they're not
      while( (*s1!=0) && (*s2!=0) )
      { // loop until either string runs out
         if(*s1!=*s2) return 1; // check if they match
         s1++; // skip to next character
         s2++;
      }
      if( (*s1==0) && (*s2==0) ) // did both strings run out at the same length?
          return 0;
      return 1; // one is longer than the other
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might seem like a stupid question I admit. But I'm in a small
This might seem like a weird question, but bear with me. I'd like to
Ok sorry this might seem like a dumb question but I cannot figure this
This might seem ridiculously simple, but I've been getting all kinds of error depending
This might seem an easy question for some, but I am struggling with it.
This might seem like a ridiculous question since I'm quite inexperienced in .NET. Is
Firstly, This might seem like a long question. I don't think it is... The
I know this might seem a controversial question but it really is not meant
This question might not seem programming related at first, but let me explain. I'm
I am just looking for some guidelines, as this might seem like a very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.