Write a c program to input your full forename, C/C++ Programming

Assignment Help:

Write a C program to input your full forename and full surname. e.g James McCarren and display in one string your complete initial and surname i.e J McCarren . Your initial should always be in upper case.

We could use pointers or char arrays let us do both
 
Answer: pointers
 
  #include
  #include
  /* malloc's prototype is in stdlib.h */
  #include
  /* toupper's prototype is in ctype.h */
  #include
  void main()
    {
    char prompt;
    
 
     Date: 26th August 2012 
    Version 1.0 
    Function : Example to show string manipulation       
     Modifications:   none*/
  char *text,*forename,*surname;
/* We must allocate space for the strings say 80 chars  so we use 81 because the terminator takes 1
space*/
  text = (char *)malloc(81);
  forename = (char *)malloc(81);
  surname = (char *)malloc(81);
  if ((text == NULL)|| (forename == NULL) || (surname== NULL))
  {
  printf("Memory full Error type -1 \n\r");
  exit(1);
  }
  printf("Please enter in your fore and surname name\n\r");
  /* Note no address operator required because text is an address 
   Scanf will read up to a white space and assign that to forename 
   the rest will be assigned to surname*/
  scanf("%s%s",forename,surname);
  /* We can extract the initial of the forename and store in in temp*/
  *text = toupper(*forename);
  *(text+1) = ' ';
  *(text+2) = '\0';
  /*We can now add together the two strings */
  strcat(text,surname);
  printf("Hello %s\n\r",text); 
  printf("Press and key to exit \n\r");
  scanf("\n%c",&prompt);
  }


Related Discussions:- Write a c program to input your full forename

Develop a telephone billing system, Project Description: My project is a...

Project Description: My project is about telephone billing system. This project was my project in my college life. The project is quite easy, i needed C++ programming language..

Program for memory optimization of c / opencl code, Program for Memory Opti...

Program for Memory Optimization of C / OpenCL Code Project Description: This is possibly a very simple project for someone with an excellent knowledge of C and OpenCL. That,

C, A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P...

A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concatenation. For a string of the c

Explain zero based addressing, Explain zero based addressing. - Array s...

Explain zero based addressing. - Array subscripts always start at zero. - These subscript values are used to identify elements in the array. - As subscripts start at 0, a

Describe overloading??, A: Along with the C++ language, you can overload op...

A: Along with the C++ language, you can overload operators and functions. Overloading is the practice of supplying more than one definition for a provided function name in the same

I need quantitative trading platform, Project Description: Need someone ...

Project Description: Need someone to prepare a trading platform and sophisticated trading strategy. Must have knowledge and experience in most of these: QuickFIX, Esper, Quan

Program to track the hours an employee worked , Description: Create a...

Description: Create a program that allows the user to track the hours an employee worked in a week. How much the employee was paid and any extra hours worked (overtime pay).

Describe how a structure differs from a union, Question : (a) How does...

Question : (a) How does a structure differ from an array? (b) Describe how a structure differs from a union? (c) Declare a union called ‘clothes' which consists of the

Student, Ask4. Write a query to display the columns listed below. The query...

Ask4. Write a query to display the columns listed below. The query should list each customer in which the video rental is overdue. The Days_Overdue column should calculate the numb

Operation on string - c ++ program, Operation on String - C ++ Program: ...

Operation on String - C ++ Program: Write a program to define operations on string in c++. class String {    char *char_ptr;   // pointer to string contents    int le

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd