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 does c mean before a date?
What is the difference between malloc calloc and realloc in c?
Should I learn c before c++?
hi any body pls give me company name interview conduct "c" language only
What is the difference between fread and fwrite function?
What is "Hungarian Notation"?
How do you determine whether to use a stream function or a low-level function?
What is the newline escape sequence?
How can I rethow can I return a sequence of random numbers which dont repeat at all?
Is this program statement valid? INT = 10.50;
What are inbuilt functions in c?
What is an endless loop?
What is class and object in c?
What is build process in c?
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