[HELP] Name and Surname - starting with uppercase

+1 Giorgi Aptsiauri · October 1, 2014
Hello, I was wondering how I'd be able to write a program in which we could type in our name and surname and it would print out on the screen our name and surname but both starting with an uppercase letter..
Here's what I've done so far:

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <string.h>

int main() {

char name[20];
char lastName[20];

printf("Enter your name\n");

do{

  if( strlen(name) > 20 ){
   printf("Your name is too long. Try again below\n");
  }
  scanf("%s", name);
}while( strlen(name) > 20 );



printf("Enter your last name\n");

do{

  if( strlen(lastName) > 20 ){
   printf("Your name is too long. Try again below\n");
  }
  scanf("%s", lastName);
}while( strlen(lastName) > 20 );



printf("You full name is: %s %s", name, lastName );


return 0;
}

It prints exactly what we type in. I want to use toupper() but I don't know how. Any idea, or suggestions?

Post a Reply

Replies

Oldest  Newest  Rating
0 Maria Belyaeva · October 3, 2014
Try this

name[0]=toupper(name[0]);
lastName[0]=toupper(lastName[0]);

printf("You full name is: %s %s", name, lastName );
0 Giorgi Aptsiauri · October 4, 2014
Thanks. Helped me.  It works fine now. 


#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <string.h>

int main() {

char name[20];
char lastName[20];

printf("Enter your name\n");

do{

  if( strlen(name) > 20 ){
   printf("Your name is too long. Try again below\n");
  }
  scanf("%s", name);
}while( strlen(name) > 20 );



printf("Enter your last name\n");

do{

  if( strlen(lastName) > 20 ){
   printf("Your name is too long. Try again below\n");
  }
  scanf("%s", lastName);
}while( strlen(lastName) > 20 );

name[0]=toupper(name[0]);
lastName[0]=toupper(lastName[0]);

printf("You full name is: %s %s", name, lastName );


return 0;
}
  • 1

C

107,202 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator