User Profile
Collapse
-
donbock replied to I was sent this code and can't figure out why I keep getting "Incomplete Data type Errorin CWhere is struct MenuItem defined? Perhaps you need to include another header file. -
Suppose all three of your numbers are equal to each other ... all of the if tests will fail, max will be uninitialized, and nothing will print.
People don’t always do what you expect. What would you like to happen if the user types xyz instead of a number?
Your code doesn’t scale well. Suppose tomorrow you need to change your program to find the maximum of four numbers instead of three? Every if condition has to change...Leave a comment:
-
Look of Sieve of Erastothenes. That may be a more efficient algorithm for finding all the prime numbers in a given range.Leave a comment:
-
As weaknessforcats said 7y ago, the C Standard allows compiler implementations substantial flexibility regarding the internal representation for the various types.
Standard library header <limits.h> provides a method for the compiler implementation to tell an application program some details of the implementation-defined internal representation of integral types.- INT_MIN and INT_MAX are the minimum negative / maximum positive
Leave a comment:
-
qsort is passed a pointer to an unsorted array. It sorts the contents of that array. I was suggesting that this could be interpreted as returning multiple values. (In the sense that it returns all the values of the sorted array.)
div and ldiv return a single structure that contains two members: quotient and remainder. I was suggesting that this could be interpreted as returning two values.
Perhaps I didn't understand...Leave a comment:
-
What a curious exam question. No matter what answer you give, nobody can say you're wrong, but nobody can say you're right either.Leave a comment:
-
Are you asking the question or are you offering advice?
Some of the standard library functions return multiple values (qsort, div, ldiv, etc). They illustrate just a few of the many possible strategies for doing this. I think it is more useful to assess each strategy based on the limitations of your program. For example, maybe thread-safety is important to you, maybe it isn't.
The only technique that comes to mind as...Leave a comment:
-
Line 7 defines pool as an array of struct record.
Line 29 seeks to change pool to point at a newly allocated block of memory. You can’t do this because pool is not a variable (the various array elements are variables, but not pool). Formally, pool is an rvalue; but you can only assign new values to lvalues.
Line 29 allocates a block of memory that is the same size as the POOL_SIZEth element of the pool array. However there isn’t...Leave a comment:
-
In the old days, a common source of bugs in C was from argument type mismatches between a function call and the function definition. For example, passing a double when you call the function but the function itself expected an int. The introduction of function prototypes with ANSI C in 1989 made that kind of bug much less common -- to the point where it may not occur to you to even look for it. However it can still occur.
For example,...Leave a comment:
-
My earlier reply was incomplete. Even if both variable1 and variable2 were ints (making the argument expression int), the %u conversion specifier still causes the argument value to be converted to unsigned int inside printf().
To print the expected value of -3:- Declare variable1 as int.
- Change %u to %d.
Leave a comment:
-
Lines 19-26 and 34 have the increment (++) operator. Which do you intend to increment -- pointer p or the thing pointed at by p? Will the tricky looking parentheses and cast achieve your intention?
Notice that argument p is a void*. That means the compiler doesn't know the type of the thing pointed at by p, so it doesn't know the size of the thing pointed at by p, so it doesn't know how much to increment the pointer by. The code tries to get...Leave a comment:
-
What compiler are you using?
Maybe you need to update to the latest version.Leave a comment:
-
-
What is going wrong with your code?- Compiler error?
- Run-time fault?
- Unexpected result?
- Something else?
It helps if you tell us the result you got and how it differs from the result you expect.Leave a comment:
-
There are lots of possibilities here. Please show us what you have. Post the relevant filenames and function definitions, declarations, and prototypes like this:
Code:[B]header1.h[/B] float func(…); [B]file1.c[/B] static int func(…) {…} [B]file2.c[/B] #include "header1.h" float func(…) {…} [B]file3.c[/B] double func(); double func(…) {…}
Leave a comment:
-
-
-
-
-
No activity results to display
Show More
Leave a comment: