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 / vignesh1988i
#include<stdio.h>
#include<conio.h>
void main()
{
char str[100],temp;
printf("enter the string :");
gets(str);
for(int i=0,j=0;str[j]!='\0';j++)
{
if(str[j]!=' ')
{
if(str[j+1]==' ')
{
temp=str[j];
str[j]=' ';
str[i]=temp;
i=i+2;
str[i-1]=' ';
}
else if(str[j+1]!=' ')
{
str[i]=str[j];
i++;
}
}
str[i]='\0';
printf("%s",str);
getch();
}
| Is This Answer Correct ? | 8 Yes | 6 No |
Post New Answer View All Answers
Explain how can I write functions that take a variable number of arguments?
Add Two Numbers Without Using the Addition Operator
What is 02d in c?
Is python a c language?
Explain that why C is procedural?
Find duplicates in a file containing 6 digit number (like uid) in O (n) time.
Why is it that not all header files are declared in every C program?
Do pointers take up memory?
What is the use of typedef in structure in c?
What is the general form of a C program?
Can 'this' pointer by used in the constructor?
Tell me the use of bit field in c language?
Linked lists -- can you tell me how to check whether a linked list is circular?
largest Of three Number using without if condition?
What is the use of #include in c?