CompuServe Thread

#THIN C vs.THINK C

3 messages in this thread
#7126From: Michael W. Fordice, PhDJul 18, 1993 7:19 PM
I have been "learning" C for a while. I started by purchasing the Dave Mark book "Learn C on the Mac" which includes THIN C. All's well with the examples in the book. BTW, if anyone asks you about THIN C, be sure to tell them that you must have 32-bit addressing OFF for THIN C to run. Now then, I just got THINK C 6.0 and decided that a good learning tool (in addition to the THINK C tutorial examples) would be to convert the THIN C examples to THINK C. So I started to do just that. In each case, one must change from "ansi.lib" (THIN C version) to "ansi" (THINK C version). No big deal. The first several examples in Mark's book ran just fine in THINK C. Then I got to "isOdd." I cannot get this beast to run in the THINK C environment. I get an error message "wrong number of arguments for the function 'printf'" (in Line 10) every time I try to compile. The code is: main() { int i; for ( i = 1; i <= 20; i++ ) { printf( "The number %d is ", i ); if ( (i / 2) * 2 == i ) printf( "even" ); <—–ERROR HERE!!! else printf( "odd" ); if ( (i / 3) * 3 == i ) printf( " and is a multiple of 3" ); printf( ".\n" ); } } in case you do not have THIN C. Would appreciate a comment from someone more knowledgable than I. Why does this code execute perfectly in THIN C but not so in THINK C? Thanks!
#7128From: Steve StockmanJul 18, 1993 9:29 PM
Michael: Did you #include <stdio.h> in your source file? Think C 6 is much stricter on prototype checking than is Thin C or previous versions of Think C. Without the the prototype from <stdio.h>, the compiler doesn't realize that printf has a variable argument list; from your first reference, it infers the prototype int printf (char *, int); Of course, none of your subsequent uses of printf conform to this prototype, hence the error. Steve
#7174From: Michael W. Fordice, PhDJul 19, 1993 7:24 PM
Steve, Thanks, #include <stdio.h> solved the problem. Interesting lesson. As I mentioned, I'm new to this stuff and am plowing through. Thanks for taking the time to respond…and I'm about 100% sure there will be more questions! Mike