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
Linked list is a Linear or non linear explain if linear how it working as a non linear data structures
What are the advantages of using Unions?
How do you define CONSTANT in C?
What is #define?
What are derived data types in c?
What does %d do in c?
how to introdu5ce my self in serco
Explain how many levels deep can include files be nested?
What are run-time errors?
provide an example of the Group by clause, when would you use this clause
Why do we use int main instead of void main in c?
How do you search data in a data file using random access method?
Function calling procedures? and their differences? Why should one go for Call by Reference?
What is static memory allocation? Explain
Is main a keyword in c?