C Program Help: Input Name & Print A/B or Error

  • Thread starter Thread starter samarth0157
  • Start date Start date
  • Tags Tags
    Program
Click For Summary

Discussion Overview

The discussion revolves around a request for assistance in writing a C program that inputs a name and prints the name if the first character is 'a' or 'b', otherwise printing an error message. The scope includes programming concepts and coding practices related to C language.

Discussion Character

  • Homework-related
  • Technical explanation

Main Points Raised

  • A participant requests a C program to input a name and conditionally print it based on the first character.
  • Another participant emphasizes that the forum does not provide direct homework solutions and suggests the user should demonstrate effort before receiving help.
  • One participant mentions the importance of understanding strings and pointers in C, providing a pseudo code outline for the solution.
  • A later reply suggests that pointers may not be necessary and proposes a simpler approach by directly comparing the first element of the string.

Areas of Agreement / Disagreement

Participants generally agree that the original request falls under homework help, but there is no consensus on how to best approach the coding problem, with differing opinions on the necessity of pointers.

Contextual Notes

Limitations include the lack of specific details about the user's current understanding of C programming concepts such as strings and conditionals.

samarth0157
Messages
1
Reaction score
0
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.
 
Physics news on Phys.org
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
 
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 don't 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:
samarth0157 said:
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.
 

Similar threads

Replies
4
Views
3K
  • · Replies 12 ·
Replies
12
Views
4K
Replies
7
Views
3K
  • · Replies 23 ·
Replies
23
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 22 ·
Replies
22
Views
6K
Replies
9
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
Replies
8
Views
7K
  • · Replies 9 ·
Replies
9
Views
4K