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
List out few of the applications that make use of Multilinked Structures?
Is it acceptable to declare/define a variable in a c header?
Write a C program to accept a matrix of any size. Find the frequency count of each element in the matrix and positions in which they appear in the matrix
Why ca not I do something like this?
What is wrong with this program statement?
Why functions are used in c?
Why is c used in embedded systems?
How can I find out the size of a file, prior to reading it in?
Is c easier than java?
What is hungarian notation? Is it worthwhile?
What would the following code segment printint k = 8;docout << "k = " << k << " ";while k++ < 5; a) 13 b) 5 c) 8 d) pointers
if (i = 0)printf ("True"); elseprintf("False"); Under what conditions will the above print out the string "True" a) Never b) Always c) When the value of i is 0 d) all of the above
In which header file is the null macro defined?
write a c program to find the sum of five entered numbers using an array named number
What are the disadvantages of external storage class?