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


Please Help Members By Posting Answers For Below Questions

You are to write your own versions of strcpy() and strlen (). Call them mystrcpy() and mystrlen(). Write them first as code within main(), not as functions, then, convert them to functions. You will pass two arrays to the function in the case of mystrcpy(), the source and target array.

1783


In cryptography, you could often break the algorithm if you know what was the original (plain) text that was encoded into the current ciphertext. This is called the plain text attack. In this simple problem, we illustrate the plain text attack on a simple substitution cipher encryption, where you know each letter has been substituted with a different letter from the alphabet but you don’t know what that letter is. You are given the cipherText as the input string to the function getwordSets(). You know that a plain text "AMMUNITION" occurs somewhere in this cipher text. Now, you have to find out which sets of characters corresponds to the encrypted form of the "AMMUNITION". You can assume that the encryption follows simple substitution only. [Hint: You could use the pattern in the "AMMUNITION" like MM occurring twice together to identify this]

1958


How do I read the arrow keys? What about function keys?

612


What is a macro?

656


the maximum length of a character constant can be a) 1 character b) 8 characters c) 256 chaacters d) 125 characters

1800






What is bubble sort technique in c?

592


What are reserved words with a programming language?

604


What is #line in c?

562


main() { printf("hello"); fork(); }

697


What is floating point constants?

689


‎How to define structures? · ‎

626


Explain how can I prevent another program from modifying part of a file that I am modifying?

639


How do you define CONSTANT in C?

651


Is main is a keyword in c?

607


What is NULL pointer?

675