AD1

Thursday, 2 February 2017

Remove all blank spaces in a string

Write a C program to remove all the blank spaces from a string.
as example if string is "hello world , C programming" then the output will be "helloworld,Cprogramming"

#include <stdio.h>
#include <string.h>
int main()
{
char input_string[100];char output_string[100];// two char arrays (two strings)
printf("enter string with spaces\n");
gets(input_string);// you can not use scanf() as it do not accept string with spaces
int i=0;int j=0;
while(input_string[i]!='\0')
{
if(input_string[i]!=' ')
{
output_string[j]=input_string[i];
i++;
j++;
}
else
{
i++;
}
}
output_string[j]='\0';//terminate o/p string with null character
printf("input string without spaces \n");
puts(output_string);
return 0;
}
view raw remove.c hosted with ❤ by GitHub

No comments:

Post a Comment