Dr. A.P.J. Abdul Kalam Technical University, Lucknow
KCS151 / KCS251 Programming for Problem Solving - Using C Language
Lab Exercises
32. Write a program to remove all the blank space from the string & print it, also count the no of characters.
/*
File: Prgrm32.c
Author: Aditya Saini
Date: Jan 18, 2021
Description: Program to remove all the blank space from the string & print it, also count the
no of characters.
*/
#include <stdio.h>
#include <string.h>
int main (void)
{
char str[50];
int char_count;
int len;
int i, j;
//Input string
printf ("Input String: ");
gets (str);
//Remove blank space and count character
len = strlen (str);
i = 0;
for (i = 0; i <= len - 1; i++)
{
if (str[i] == ' ' || str[i] == '\t')
{
for (j = i; j <= len - 2; j++)
str[j] = str[j + 1];
len--;
i--;
}
}
str[len] = '\0';
//Print new string after removing space
printf ("New String after removing blank space: %s", str);
//Print no of characters
printf ("\nNumber of characters: %d", len);
};
Output
Input String: www. digital g1 .com
New String after removing blank space: www.digitalg1.com
Number of characters: 17
No comments:
Post a Comment
Please do not post spam links.