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
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.
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]
How do I read the arrow keys? What about function keys?
What is a macro?
the maximum length of a character constant can be a) 1 character b) 8 characters c) 256 chaacters d) 125 characters
What is bubble sort technique in c?
What are reserved words with a programming language?
What is #line in c?
main() { printf("hello"); fork(); }
What is floating point constants?
How to define structures? ·
Explain how can I prevent another program from modifying part of a file that I am modifying?
How do you define CONSTANT in C?
Is main is a keyword in c?
What is NULL pointer?