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
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]
An instruction which is analysed and acted upon by the processor prior to the compiler going its work a) directive b) constructive c) constant d) absolute mode
Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10
what are the advanced features of functions a) function declaration and prototypes b) calling functions by value or by reference c) recursion d) all the above
what do you mean by enumeration constant?
the real constant in c can be expressed in which of the following forms a) fractional form only b) exponential form only c) ascii form only d) both a and b
What is formal argument?
How can I prevent another program from modifying part of a file that I am modifying?
int i=10; printf("%d %d %d", i, i=20, i);
What does the error message "DGROUP exceeds 64K" mean?
What is the -> in c?
What is #include stdio h?
What is c mainly used for?
What is wrong with this program statement?
What is the difference between far and near ?