- #1
- 350
- 203
Note: this is not a homework question!
The problem that this program should solve is turn a input like this:(no space and the end of the input string)
into something like this:
But I keep getting an excess line at the bottom of all outputs like this:
So my code send an excess ‘\n’,but I can’t find which part of my code went wrong.
My code:
The problem that this program should solve is turn a input like this:(no space and the end of the input string)
Code:
james shawn charles nicholas
Code:
James
Shawn
Charles
Nicholas
Code:
James
Shawn
Charles
Nicholas
<-This line
My code:
Code:
#include<iostream>
#include<string.h>
using namespace std;
char n[1000];
int lcv = 0;
int main(){
cin.getline(n,300);
cout<<char(toupper(n[0]));
for(unsigned short lcv = 1;lcv<strlen(n)-1;lcv++){
while(n[lcv] != ' '){
if(lcv>=strlen(n))
break;
cout<<n[lcv];
lcv++;
}
cout<<'\n'<<char(toupper(n[lcv+1]));
lcv++;
}
return 0;
}
Last edited: