+1 vote
1.5k views
in Programming by (98.9k points)
reopened by
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

2 Answers

+1 vote
by (98.9k points)
selected by
 
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 (98.9k points)
edited
Code is correct hence flags are cleared ! if any problem with solution comment !
by (245 points)
edited
Thanks for the answer well you can add some outputs too !  I am adding in answer w8
0 votes
by (245 points)
edited

Output of the Code ::


image

Related questions

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

554 users

...