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"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
No comments:
Post a Comment