+ 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

13th Mar 2018, 2:09 PM
abhijeet
abhijeet - avatar
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; }
13th Mar 2018, 2:24 PM
Hatsy Rei
Hatsy Rei - avatar
+ 10
Also, if you included <string>, why not use string.
13th Mar 2018, 2:25 PM
Hatsy Rei
Hatsy Rei - avatar
+ 6
thanks
13th Mar 2018, 5:24 PM
abhijeet
abhijeet - avatar