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
What is a #include preprocessor?
What does %p mean c?
Explain built-in function?
Explain how can I remove the trailing spaces from a string?
Explain what math functions are available for integers? For floating point?
which is conditional construct a) if statement b) switch statement c) while/for d) goto
What does 3 mean in texting?
Differentiate between functions getch() and getche().
Difference between pass by reference and pass by value?
Can you return null in c?
WHICH TYPE OF JOBS WE GET BY WRITING GROUPS .WHEN THE EXAMS CONDUCTED IS THIS EXAMS ARE CONDUCTED EVERY YEAR OR NOT.PLS TELL ME THE ANSWER
How can you determine the maximum value that a numeric variable can hold?
Write a Program to find whether the given number or string is palindrome.
How to set file pointer to beginning c?
What is the mean of function?