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 / 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 |
Post New Answer View All Answers
What is bss in c?
What is calloc malloc realloc in c?
What is the difference between local variable and global variable in c?
How can I generate floating-point random numbers?
why return type of main is not necessary in linux
‘ C’ PROGRAME TO SHOW THE TYPE OF TRANGLE BY ACCEPTING IT’S LENGTH .
What is output redirection?
Can 'this' pointer by used in the constructor?
Why & is used in c?
Explain how can I prevent another program from modifying part of a file that I am modifying?
Define Spanning-Tree Protocol (STP)
write a C program: To search a file any word which starts with ?a?. If the word following this ?a? starts with a vowel.Then replace this ?a? with ?a? with ?an?. redirect with the output onto an output file.The source file and destination file are specified by the user int the command line.
What are Macros? What are its advantages and disadvantages?
Why doesnt this code work?
Can you subtract pointers from each other? Why would you?