So... why does this code compile and run but the
length function only produces zero no matter what string is input?
... about programming, growing up in the 1970's and 80's, games, science fiction, working in a charity book shop, films, spending too much time watching television, living in Basildon and Essex, and whatever else emerges from my fevered imagination. If you're reading this, it's your fault you clicked on the link: I am not responsible for your actions.
length function only produces zero no matter what string is input?
#include <stdio.h>
#define FIRST_PART 7
#define LAST_PART 5
#define ALL_PARTS FIRST_PART + LAST_PART
int main() {
printf("The square of all the parts is %d\n",
ALL_PARTS * ALL_PARTS);
return (0);
}
#include <stdio.h>
char line[100];/* line of input data */
int height; /* the height of the triangle
int width; /* the width of the triangle */
int area; /* area of the triangle (computed) */
int main()
{
printf("Enter width height? ");
fgets(line, sizeof(line), stdin);
sscanf(line, "%d %d", &width, &height);
area = (width * height) / 2;
printf("The area is %d\n", area);
return (0);
}
1
|
#define MAX_COUNT 20
|
scanf statement? Afterwards, I asked one of the other guys, Richard, who had the same answer and just tried it out on the compiler, and we got it right!int i = 12;
if (i = 13){
printf("Does this happen or not??");
}
(Yes, I know it's a mistake, but does it still work and what happens?)
int x = 10;
int y = 10;
printf("The value of x is %d and x++ is %d\n", x, x++);
printf("but the value of y is %d and ++y is %d\n", y, ++y);