Write a program that accepts a string where multiple spaces
are given in between the words. Print the string ignoring
the multiple spaces.
Example:
Input: ā We.....Are....Student ā Note: one .=1 Space
Output: "We Are Student"
Answer Posted / pramod
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int i,j,k,len;
char a[100];
printf("Enter the String\n");
gets(a);
printf("The Given String is %s \n",a);
len=strlen(a);
for(i=0; i<len;i++)
{
if(a[i] == ' ')
{
if(a[i+1]==' ')
{
int j=i+1;
while(a[j]==' ')
{
j++;
len--;
}
for(k=i+1;a[j]!=NULL;)
{
a[k++]=a[j++];
}
}
}
}
a[i]='\0';
printf("The Resulted String is %s\n ",a);
}
Is This Answer Correct ? | 5 Yes | 1 No |
Post New Answer View All Answers
5 Write an Algorithm to find the maximum and minimum items in a set of ānā element.
What is scope rule in c?
How can I recover the file name given an open stream or file descriptor?
explain what is a newline escape sequence?
What is the use of structure padding in c?
Why calloc is better than malloc?
how logic is used
Define Array of pointers.
Is main is user defined function?
What are Macros? What are its advantages and disadvantages?
write a program to display all prime numbers
What is %s and %d in c?
Which type of language is c?
When should I declare a function?
What is #line?