+ 9
Help plz c++
i want to find number of words as well as replace the space between two words by hyphen eg hi everyone output: hi-everyone 2 how can i do it? https://code.sololearn.com/cpz4s4xf93ir/?ref=app
3 Antworten
+ 11
#include <iostream>
#include<string>
using namespace std;
int main() {
int i,l,w=0;
char line[80];
cin.getline(line,80);
l=strlen(line);
for(i=0;i<l;i++)
{
if(line[i]==' ') {
w++ ;
line[i]='-';
}
}
cout<<line<<endl;
cout<<w+1;
return 0;
}
+ 10
Also, if you included <string>, why not use string.
+ 6
thanks