C code to remove spaces or excess blanks from a string, For example consider the string
"c programming"
There are two spaces in this string, so our program will print a string
"c programming". It will remove spaces when they occur more than one time consecutively in string anywhere.
C programming code
#include <stdio.h>
int main()
{
char text[100], blank[100];
int c = 0, d = 0;
printf("Enter some text\n");
gets(text);
while (text[c] != '\0')
{
if (!(text[c] == ' ' && text[c+1] == ' ')) {
blank[d] = text[c];
d++;
}
c++;
}
blank[d] = '\0';
printf("Text after removing blanks\n%s\n", blank);
return 0;
}
"c programming"
There are two spaces in this string, so our program will print a string
"c programming". It will remove spaces when they occur more than one time consecutively in string anywhere.
C programming code
#include <stdio.h>
int main()
{
char text[100], blank[100];
int c = 0, d = 0;
printf("Enter some text\n");
gets(text);
while (text[c] != '\0')
{
if (!(text[c] == ' ' && text[c+1] == ' ')) {
blank[d] = text[c];
d++;
}
c++;
}
blank[d] = '\0';
printf("Text after removing blanks\n%s\n", blank);
return 0;
}
This comment has been removed by a blog administrator.
ReplyDelete