Write a program to replace all spaces in a string with user

Write a program to replace all spaces in a string with user given character input. Use a character array to store the string given by the user and use a function to handle the replacing task.

Solution

#include<stdio.h>

int main()

{

char arr[50];

char ch;

printf(\"enter string : \");

scanf(\"%s\",&arr);

printf(\"\ enter a character to replace all spaces in string \");

scanf(\"%c\",&ch);

printf(\"\ old string :%s\",arr);

char old[50];

old=arr;

for(int i=0;i<arr.length;i++)

{

if(arr[i]==\' \')

arr[i]=ch;

}

printf(\"new string :%s\",arr);

return 0;

}

 Write a program to replace all spaces in a string with user given character input. Use a character array to store the string given by the user and use a functi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site