0 votes
5 views
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
in Programming by (5.4k points) | 5 views

1 Answer

0 votes
Best answer
#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;
}
by (5.4k points)
500 questions
477 answers
8 comments
12 users