C program help needed

  • #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.
 

Answers and Replies

  • #2
MATLABdude
Science Advisor
1,657
4
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):
https://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_Programming/Simple_input_and_output#Input_using_scanf.28.29

...and how to structure an if statement?
http://en.wikibooks.org/wiki/C_Programming/Control#The_If-Else_statement
 
  • #3
76
0
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')
 
Last edited:
  • #4
berkeman
Mentor
59,986
10,189
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.
 

Related Threads on C program help needed

Replies
8
Views
2K
  • Last Post
Replies
8
Views
5K
  • Last Post
Replies
5
Views
2K
  • Last Post
Replies
1
Views
3K
  • Last Post
Replies
7
Views
1K
Replies
1
Views
3K
  • Last Post
Replies
2
Views
1K
Replies
8
Views
2K
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
6
Views
987
Top