Modify the code below which will read single characters at a time and capitalize
ID: 3919400 • Letter: M
Question
Modify the code below which will read single characters at a time and capitalize each letter using toupper() in a SPECIFIED COLUMN of EACH word (NOT "ONE" WORD), which column is specified on the command line argument argv[1].
Make sure the rest of the word is lowercase using tolower(). Use isspace() in order to check for spaces in the text files or from a user input.
Example: echo "hello WORLD" | capitalizeone 2 hEllo wOrld
#include <cstdio> #include <iostream> using namespace std; int main () { int c ; // yes, read chars in as ints. c = cin.get() ; while (!cin.eof()) { cout.put(c) ; c = cin.get() ; } cout.put(' ') ; // sometimes this is needed: you'll know when }
Explanation / Answer
#include <cstdio>
#include <iostream>
using namespace std;
int main ()
{
int c ; // yes, read chars in as ints.
c = cin.get() ;
int i=0;
i++;
while (!cin.eof())
{
if(c==' ')
i=0;
if(i==2)//capitalizing...only column2 of each word
{
cout.put(toupper(c)) ;
}
else
cout.put(tolower(c)) ;
i++;
c = cin.get() ;
}
cout.put(' ') ; // sometimes this is needed: you'll know when
}
output:
hello WORLD
hEllo wOrld
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.