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 “
Output: "We Are Student"



Write a program that accepts a string where multiple spaces are given in between the words. Print ..

Answer / vadivel t

#include<stdio.h>
main()
{
char *p, *q, *q1;
p = (char *)malloc(200);
q = (char *)malloc(200);
q1 = q;
printf("ENTER THE SENTENCE: \n");
p = 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 0 No

Post New Answer

More C Interview Questions

Blade logic interview question. 1st round is a written tests with 15 multiple questions from c and c++. All are simple basic question. Like int main () { Int i=65; Return printf(“%c”, i); } 2nd and 3rd round is technical interview. The position for which I was interview was core UNIX and c. Yes it is for system programming. The company has product name blade server. For their server they are creating their own command for their purpose. Example cd command. We can implement it in a c program by using the chdir() function. So the question asks related to PID, fork, pipe, shared memory, signal. Write a program in c which will act as cp command.

1 Answers   BladeLogic, Infosys,


Write a c program to find, no of occurance of a given word in a file. The word is case sensitive.

2 Answers  


IS Doon college of Engn.. has good faculty

1 Answers  


Write a program to generate prime factors of a given integer?

2 Answers  


What is a class?

3 Answers  






why we wont use '&' sing in aceesing the string using scanf

0 Answers   HCL,


tell me the full form of c?

2 Answers  


When I tried to go into a security sites I am denied access and a message appeared saying 'applet not initialize'. How can I rectify this problem.

0 Answers   HCL,


If you know then define #pragma?

0 Answers  


write a programme that inputs a number by user and gives its multiplication table.

2 Answers  


Difference between exit() and _exit() function?

0 Answers  


Can you please compare array with pointer?

0 Answers  


Categories