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> 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<string.h>
#include<stdlib.h>
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
Post a Comment