Question:
C Program Can not seem to get this figured out. Please help me fix this.?
roze
2010-12-07 21:15:37 UTC
this program is suppose to give the number of letters in the name that is typed in. also need that name to come out in upper case on the screen. I am having alot of trouble with this. Please help me. I do not honestly know what I am doing wrong. I am lost and do not have anyone close that I can turn to for help.Thank you in advance for all of your help.

#include
#include
#include




main()
{

char name1[20];
char letter = 'a';

printf("\n Please enter your first name.\n");
scanf("%s", &name1);
printf("Before toupper: %c\n", letter);
letter = toupper(letter);
printf("\nThe length of your name is: %d\n", strlen(name1));
printf("\n Your name is: %s",name1);
printf("\nAfter toupper: %c\n", letter);




}
Four answers:
Wajahat Karim
2010-12-07 22:54:53 UTC
you have 2 problems in code.....



1. When we take any string using scanf(), we do not need to specify & before parameter.

2. toupper() receives char not any string....

3. You have missed writing void at start of main ()



here i have modified code for you....



#include

#include

#include



void main()

{



char name1[20];

char upperName[20]; //for uppercase

//char letter = 'a'; there is no need of character letter



printf("\n Please enter your first name.\n");

scanf("%s", name1);

printf("\nThe length of your name is: %d\n", strlen(name1));

printf("\n Your name is: %s",name1);

for (int i=0; i<20; i++)

{

upperName[i] = toupper(name1[i]);

}

printf("\nAfter toupper: %s", upperName);



}



i hope you got what you were looking for.....
srt
2010-12-08 05:40:26 UTC
http://www.tutorialspoint.com/ansi_c/c_toupper.htm

says:

int toupper(int c);



Problems:

1- there is not any relation with letter and name1 in your code. When you run the above code you should see A uppercase off a. You are converting letter to upper but it has only a.

2- toupper accepts a character. Therefore you have to go through loop and convert each character of the name1 to upper

int n,i;

...

n=strlen(name1)

for(i=0;i
{

printf("%c",toupper(name1[i]))

}
The Phlebob
2010-12-08 05:25:36 UTC
You're taking in the name in name1, but you're setting letter to upper case. How does letter relate to name1? (I think you have to get a better grasp on a concept here.) Remember, "letter" has no intrinsic meaning to the computer. It doesn't realize that a name is made up of "letters".
anonymous
2010-12-08 05:28:18 UTC
printf("\n Your name after toupper is: %s",toupper(name1));



i assume to get the length you would do

printf("\nThe length of your name is: %d\n", length(name1));



try it but i dont use c so it could be wrong


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...