1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: C program help needed

  1. Feb 21, 2012 #1
    GIVE A program of c to input a name and print the name if the first char of name is a or b else print error message.
  2. jcsd
  3. Feb 21, 2012 #2


    User Avatar
    Science Advisor

    Welcome to PhysicsForums!

    We don't do homework (or things that aren't homework that nevertheless look like homework) for people here. Also, homework should go in the appropriate homework help sub-section (I've contacted a moderator to get this post moved where other people can help you help yourself, as Jerry Maguire says):

    To get you started, do you know C? Specifically, how to make use of scanf():

    ...and how to structure an if statement?
  4. Feb 21, 2012 #3
    You will need to know about strings and pointers. Have you gone over those yet?

    pseudo code
    get input from user in a string(char array)
    use pointer to check first letter of name
    if (first letter is 'a' or 'b') print name
    else dont print name

    Does this help you? If not let me know I will try and explain better.

    EDIT: Actually you do not need to know about pointers I suppose you can just compare the first element of the string

    char name[50];
    get input
    Last edited: Feb 21, 2012
  5. Feb 21, 2012 #4


    User Avatar

    Staff: Mentor

    Your thread has been moved to the Homework Help section of the PF.

    You need to show some effort on your part before we can be of any more help.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook