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

  • SEARCH
  • Home
  • 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 7831603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:48:20+00:00 2026-06-02T11:48:20+00:00

My .c programme gives an object a ‘name’ when its created. I need to

  • 0

My .c programme gives an object a ‘name’ when its created. I need to be able to excute different tasks depending on that name. I very new to this and have tried a couple of ways with no success. Here is what I had come up with..

if (name ==  "james"){

    //Do a bunch of stuff
    } 
if (name ==  "tom"){

    //Do a bunch of stuff
    } 

This was not successful. Is there a way so that if the ‘name’ is one thing it wont execute the others?

Thankyou so much for any help

  • 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-06-02T11:48:21+00:00Added an answer on June 2, 2026 at 11:48 am

    In C, a string is defined as a sequence of characters which are terminated with \0. A string constant is normally represented within `”, for example, char a[10] = “hello”.

    In order to compare two strings, you can use library functions like strcmp() which is available in string.h. Do man strcmp to read more about this function.

    #include <stdio.h>
    #include <string.h>
    
    int main()
    {
            char name[] = "tom";
    
            if (strcmp(name, "tom") == 0) {
                printf("name is tom! \n");
            } else if (strcmp(name, "bob") == 0) {
                printf("name is bob! \n");
            } else {
                printf("who is this?! \n");
            }
    
            return 0;
    }
    

    The strcmp could have been implemented in the following ways (array and pointer versions for your reference)

    int strcmp1(char a[], char b[])
    {
            int i=0;
            while (a[i] == b[i]) {
                    if (a[i] == '\0')
                            return 0;
                    i++;
            }
    
            return a[i]-b[i];
    }
    
    int strcmp2(char *a, char *b)
    {
            while (*a == *b) {
                    if (*a == '\0')
                            return 0;
                    a++; b++;
            }
            return *a-*b;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an HTML/JavaScript program that gives me a JSON object as a
I need help with pointers and memory management. I need to store different objects,
I noticed that they don't return pointers when created, but actual objects. So to
No matter how I flip this script around it still gives me Object reference
The below code gives the error The operator 'expr.[idx]' has been used an object
Scenario: I have a customer object with lazy loading enabled. I use that throughout
For my trading program, I have a Merchant class. A given Merchant object may
Changing a Linux C++ program which gives the user limited file access. Thus the
Here is a simple php program which gives a strange output. Can anyone explain
when I'm trying to compile my c program it gives me this error warning:

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.