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"
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / 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 |
Answer / vikramaditya.n
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[k] == ' ')
{
for(j=k;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 | 2 No |
#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 |
Hi all,
Its enough to have this much length of code below. And I
feel no need to have any temp variables(but i used one temp
pointer).
#include<stdio.h>
main()
{
char *p, *q, *q1;
p = (char *)malloc(100);
q = (char *)malloc(100);
q1 = q;
printf("ENTER THE SENTENCE WITH MULTIPLE SPACES: \n");
gets(p);
while(*p != '\0')
{
if(*p != ' ' || *(q -1) != ' ')
{
*q++ = *p++;
}
else
p++;
}
*q = '\0';
printf("%s", q1);
getch();
}
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / jyotsna
/* Assume ' ' at the place of '.' */
#include<conio.h>
#include<stdio.h>
void main()
{
char *s="Hello...this...is...jyotsna";
int i=0;
clrscr();
while(*s!='\0')
{
if(*s!='.')
{
printf("%c",*s);
i=0;
s++;
}
else
{
while(*s=='.')
s++;
printf(".");
}
}
getch();
}
Is This Answer Correct ? | 0 Yes | 2 No |
How do you list files in a directory?
void main() { char far *farther,*farthest; printf("%d..%d",sizeof(farther),sizeof(farthest)); }
Compare and contrast compilers from interpreters.
write a program to arrange the contents of a 1D array in ascending order
two progs are given. one starts counting frm 0 to MAX and the other stars frm MAX to 0. which one executes fast.
Is c functional or procedural?
When was c language developed?
What is static and auto variables in c?
What is quick sort in c?
what is the use of bitfields & where do we use them?
what is the different between if-else and switch statment (other than syntax)
26 Answers CTS, Oracle, Scorpos,
main() { char ch='356'; Printf("%d",ch); } *OUTPUT*:- -18 *Why?*