Skip to main content

Remove The Blank Spaces From A String Using C Programming

Remove The Blank Spaces From A String

Algorithm :-

  • Declare the iterator variable i and j of type integer in main function.
  • Enter a string through gets() function, which defined in <string.h&gt header file.
  • Pass the string in the gets() function for input string.
  • Declare an another string str1[50] to store the string without blank space.
  • Iterate using the for loop from i=0 to the last NULL character of the string ('\0').
  • Declare a integer type variable j and initialized to zero j=0 for str1().
  • Check every character of a string till the last character,
  • If the Blank Space found then skip and increment the str[i] index i for next iteration.
  • continue; is used to skip a particular iteration. Else copy that character into the str1[j] array of string.
#include<stdio.h&gt
#include<string.h&gt
#include<stdlib.h&gt
int main()
{
int i,j;
char str[50],s,str1[50];
printf("Enter a string:-");
gets(str);
j=0;
for(i=0;str[i]!='\0';i++)
{
if(str[i]==' ')
{
continue;
}
else
{
str1[j]=str[i];
j++;
}
} str1[j]='\0';
printf("\nString without blank space: %s",str1);
return 0;
}

Output:-
Enter a string :- This is my book
String without blank space: Thisismybook

Comments

Popular posts from this blog

Data Structure And Algorithm Important Topics Overview

  Overview Of Data Structures And Algorithms This post will give you the clear idea about learning data structures and algorithms . So, Data structure? => In computer science a data structure is a data organization , management and storage format that enables efficient access and modification. Or in the other words it is a way in which data is stored on a computer. Types of data structures:- Array  String Stack Queue Linked List  Binary Tree Binary Search Tree Heap Hash Table Graph Above topics, array is a linear data structure which stores the data in the sequence order, dynamic array, every data is stored in the next contiguous memory location.   String is a collection of characters. If it contains the alphabets and it also uses the digit as character. If a string is composed of numbers and characters then numbers are also treated as characters. Stack is also a linear data structure. It works either on Last In First Out or First In Last Out . It has only one ...

Fix Breadcrumbs Error And m=1? In Blogger

  Remove Breadcrumbs Errors And ?m=1 Breadcrumb is a small path. It points your location on your site. It also affects the SEO of your website.  Use canonical URL , so: data:blog.url.canonical  instead of data:blog.url. It should work for both desktop and mobile versions. It means the same URL works on both mobile and desktop without producing the ?m=1 or ?m=0. Before this, I am going to tell you what all the portions I will explain and fix your problem. First we will fix Breadcrumbs Error . This is the most dangerous for your website. Second we will remove ?m=1 and ?m=0, tags from our mobile view URL. Remove Breadcrumbs Error :- You should follow the below steps, so that you would fixed this error :- Go to blogger.com Login to blogger with your blogger email id Click on Template Click edit HTML, you have to edit HTML theme code. Press Ctr + F to open a search bar in your HTML theme code. Search for <div class='breadcrumbs' Paste the below code up to </b:loop> ...

Phonepe Wallet : Send Money From Phonepe Wallet To Bank Account

Send Money From Wallet To Bank  It is very easy to send the Phonepe wallet money to the bank account. There are some simple steps needed to perform to send the money to bank account. Whenever you got money into your phonepe wallet through any online transaction and you are not getting into your bank account because of the phonepe policy. You can not send money to your bank account directly. Only one alternative way, that will help you to send money. If you have money in your phonepe wallet, you have to buy some shares of gold from the phonepe and you have to sell that gold. On buying, it cut 3 to 4 percentage of GST but during selling, you have not to pay anything. In another words, when you buy gold, you have to pay some percentage of taxes and on selling there will not be any charges. The total amount will be transfer into the bank account. Steps Required:- First You have a phonepe account, You can login with your registered mobile number that is registered with your bank account...