What is wrong with this code such that it doesnt produce
the input reversed?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
char Space = ' ';
char LineOfText;
float count;

LineOfText = getchar();

while ((LineOfText = getchar()) != '/n');
{
count = strlen(LineOfText) - 1;
while (count >= 0)
{
putchar(LineOfText[count]);
count--;
}

}
getchar();
return 0;
}

Answers were Sorted based on User's Feedback



What is wrong with this code such that it doesnt produce the input reversed? #include <stdio.h..

Answer / ashok kumar

Actually the function strlen() returns an integer value,
but here we want to try to push that value to the float
variable. To rectify this problem declare the variable
"count" as int.

Is This Answer Correct ?    1 Yes 0 No

What is wrong with this code such that it doesnt produce the input reversed? #include <stdio.h..

Answer / sanjay bhosale

LineOfText is not an array of characters.
first while loop only stores '/n' in lineOfText.
We cant apply strlen on character we should pass the address of character array to it.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

What is cohesion and coupling in c?

0 Answers  


prog for 1st five prime numbers in 2^x - 1

0 Answers  


how could explain about job profile

0 Answers  


What is the use of ?: Operator?

0 Answers  


main() { float a=8.8; double b=8.8; if(a==b) printf("Equal"); else printf("not equal"); getch(); } what is the output? with reason

6 Answers   CSC,


What are the different types of errors?

0 Answers  


write a program to find a given no. is divisible by 3 or not without using any arthimetic operators?

3 Answers   Broadcom, TCS,


nic scientist exam

1 Answers   NIC,


Program to swap the any two elements in an array containing N number of elements?

1 Answers   Bosch, Glenwood, Ugam Solutions,


what is computer

4 Answers  


What is bss in c?

0 Answers  


What is the difference between Printf(..) and sprint(...) ?

0 Answers   InterGraph,


Categories