menu search
person
Write a C++ program to replace every space in an inputted string (less than 80 characters) with a hyphen (i.e. - )

Turbo C++ maharashtra board
thumb_up_alt 2 like thumb_down_alt 0 dislike
159 views

1 Answer

 
verified
#include<iostream.h>
#include<conio.h>
#include<string.h>

void main()
{
char str[80];
int i, len;
cout<<"Enter a string : ";
cin.getline(str,80,'\n');
len=strlen(str);
for(i=0; i<=len-1; i++)
{
if (str[i]==' ')
{
str[i]='-';
}
}
cout<<str;
}
thumb_up_alt 2 like thumb_down_alt 0 dislike
...