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


Please Help Members By Posting Answers For Below Questions

What does c mean before a date?

574


What is the difference between malloc calloc and realloc in c?

634


Should I learn c before c++?

584


hi any body pls give me company name interview conduct "c" language only

1647


What is the difference between fread and fwrite function?

627






What is "Hungarian Notation"?

627


How do you determine whether to use a stream function or a low-level function?

631


What is the newline escape sequence?

571


How can I rethow can I return a sequence of random numbers which dont repeat at all?

693


Is this program statement valid? INT = 10.50;

675


What are inbuilt functions in c?

551


What is an endless loop?

788


What is class and object in c?

577


What is build process in c?

632


How to write a code for implementing my own printf() and scanf().... Please hep me in this... I need a guidance... Can you give an coding for c... Please also explain about the header files used other than #include...

4894