I have the second half of this assignment done, but so very stuck on the lowercase to uppercase part! This is the assignment: Write a C++ program that reads in a text file ( called data10.txt), and prints to the screen the text with all extra blanks removed (that is, if there are 2 or more blanks in a row, replace them by a single blank) and changes all LOWERCASE letters to UPPERCASE letters. WATCH THAT YOU DON”T DELETE CARRIAGE RETURNS and tabs – whitespace includes tabs and carriage returns as well as blanks…so you only want to get rid of extra blank characters.
No, i'm using a program called Xcode on a Mac. I've tried to use "toupper" and it just screws up the output, ughhhh
?2011-04-27T18:23:12Z
Favorite Answer
Main problems with your program: .eof() is used for the file reading loop condition toupper(ch) is used before anything is stored in the object ch You *are* deleting "carriage returns" and tabs since you're using isspace() Because count is 1 from the beginning, you're printing an extra space before the first character of the file
Otherwise, it's a sensible program, here it is all fixed up and working (file name is different since yours was cut off by yahoo)
of course you don't have to use so many loops and branches if you don't want to... the following program does exactly the same thing (omitting file open test for brevity)
Convert lowercase letter to uppercase Converts parameter c to its uppercase equivalent if c is a lowercase letter and has an uppercase equivalent. If no such conversion is possible, the value returned is c unchanged.
Notice that what is considered a letter may depend on the locale being used; In the default C locale, a lowercase letter is any of: a b c d e f g h i j k l m n o p q r s t u v w x y z, which translate respectively to: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z.
In C++, a locale-specific template version of this function (toupper) exists in header <locale>.
hi, i will help you get to Uppercase :: fairly constructive you would be waiting to exercising consultation the thank you to get to lowercase in keeping with this occasion: #contain <stdio.h> #contain <ctype.h> #outline MAX 32 int substantial(void) { char arr[MAX],ch='0'; int i=0; printf("enter a string: "); at the same time as(ch!='n') { ch=getc(stdin); if(i<(MAX-a million)) { arr[i]=toupper(ch); i++; } } printf("%s",arr); return 0; } Regards, Javalad