Program Discussion :: Strings
92 / 60
Write a program to remove the blank space from the string without using built in function
Answer:
#include
#include
using namespace std;
int main()
{
char text[1000], blank[1000];
int c = 0, d = 0;
cout
Asked In ::
Language:
Vivek Rai
7 Jul, 2017 9:30 AM
#include <stdio.h>
int main()
{
char text[1000], blank[1000];
int c = 0, d = 0;
printf("Enter some text\n");
gets(text);
while (text[c] != '\0') {
if (text[c] == ' ') {
int temp = c + 1;
if (text[temp] != '\0') {
while (text[temp] == ' ' && text[temp] != '\0') {
if (text[temp] == ' ') {
c++;
}
temp++;
}
}
}
blank[d] = text[c];
c++;
d++;
}
blank[d] = '\0';
printf("Text after removing blanks\n%s\n", blank);
return 0;
}
Language:
Vignesh
7 Jul, 2017 9:30 AM
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
char text[1000], blank[1000];
int c = 0, d = 0;
cout<<"Enter some text\n";
gets(text);
while (text[c] != '\0') {
if (text[c] == ' ') {
int temp = c + 1;
if (text[temp] != '\0') {
while (text[temp] == ' ' && text[temp] != '\0') {
if (text[temp] == ' ') {
c++;
}
temp++;
}
}
}
blank[d] = text[c];
c++;
d++;
}
blank[d] = '\0';
cout<<"Text after removing blanks\n%s\n"<<blank;
return 0;
}