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 / santhi perumal
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,k;
char a[100];
printf("Enter the String\n");
gets(a);
printf("The Given String is %s \n",a);
for(i=0; a[i] != '\0';i++)
{
if(a[i] == ' ')
{
for(k=i+1;a[k] != '\0';k++)
{
if(a[i+1] == ' ')
{
for(j=i+1;a[j] != '\0';j++)
{
a[j] = a[j+1];
}
a[j] ='\0';
}
}
}
}
printf("The Resulted String is %s\n ",a);
}
| Is This Answer Correct ? | 3 Yes | 4 No |
Post New Answer View All Answers
What is the importance of c in your views?
Explain the difference between the local variable and global variable in c?
which of the following shows the correct hierarchy of arithmetic operations in C a) (), **, * or/,+ or - b) (),**,*,/,+,- c) (),**,/,*,+,- d) (),/ or *,- or +
what are bit fields? What is the use of bit fields in a structure declaration?
Why should I use standard library functions instead of writing my own?
What is the best way of making my program efficient?
What is local and global variable in c?
Explain the array representation of a binary tree in C.
write a program to print largest number of each row of a 2D array
What are the two types of structure?
What is keyword with example?
Ow can I insert or delete a line (or record) in the middle of a file?
Explain the difference between call by value and call by reference in c language?
Why header file is used in c?
What is atoi and atof in c?