c program help needed


by samarth0157
Tags: program
samarth0157
samarth0157 is offline
#1
Feb21-12, 05:43 AM
P: 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.
Phys.Org News Partner Science news on Phys.org
SensaBubble: It's a bubble, but not as we know it (w/ video)
The hemihelix: Scientists discover a new shape using rubber bands (w/ video)
Microbes provide insights into evolution of human language
MATLABdude
MATLABdude is offline
#2
Feb21-12, 06:01 AM
Sci Advisor
P: 1,724
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):
http://www.physicsforums.com/forumdisplay.php?f=152

To get you started, do you know C? Specifically, how to make use of scanf():
http://en.wikibooks.org/wiki/C_Progr...ng_scanf.28.29

...and how to structure an if statement?
http://en.wikibooks.org/wiki/C_Progr...Else_statement
camel-man
camel-man is online now
#3
Feb21-12, 12:16 PM
P: 55
You will need to know about strings and pointers. Have you gone over those yet?

pseudo code
declarations
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
if(name[0]=='a'||name[0]=='b')

berkeman
berkeman is online now
#4
Feb21-12, 03:57 PM
Mentor
berkeman's Avatar
P: 39,716

c program help needed


Quote Quote by samarth0157 View Post
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.
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.


Register to reply

Related Discussions
very simple program in C, help needed Programming & Computer Science 26
Help needed for simple program, would be grateful! Programming & Computer Science 2
help needed: basic javascript program Engineering, Comp Sci, & Technology Homework 8
Help needed on medical MS program selection Career Guidance 2
Formula Needed For Artillery Program General Physics 0