-4
\$\begingroup\$

I'm learning C using Mike McGraths 3rd edition. I know the book is old but I want to have a better appreciation for the changes made to C through its timeline. The compiler error is error: ‘SYSTEM’ undeclared (first use in this function).

#include <stdio.h>
#define LINE "______________________"
#define TITLE "C programming in easy steps"
#define AUTHOR "Mike McGrath"
#ifdef _WIN32
#define SYSTEM "Windows"
#endif
#ifdef Linux
#define SYSTEM "Linux"
#endif
int main()
{
    printf("\n \t %s \n \t %s \n", LINE, TITLE);
    printf("\n \t %s \n \t %s \n", AUTHOR, LINE);
    printf("\n Operating System: %s \n", SYSTEM);
    return 0;
}
\$\endgroup\$
  • \$\begingroup\$ I doubt the book is from 1956, as C didn't exist back then. Do you mean 1995, as Linux would exist by then... \$\endgroup\$ – Wim ten Brink Nov 12 at 10:40
  • \$\begingroup\$ Yes you're right my mistake. \$\endgroup\$ – Martin Nov 12 at 10:45
-1
\$\begingroup\$

The simplest fix is to replace #ifdef Linux with #ifdef linux. Take a look at this reference for more.

\$\endgroup\$
  • \$\begingroup\$ Thank you shards, the last one worked. \$\endgroup\$ – Martin Nov 12 at 10:34
  • 1
    \$\begingroup\$ @Martin Or you could use #elif. See description here \$\endgroup\$ – Peter Jennings Nov 12 at 10:53
  • \$\begingroup\$ @Peter Thanks for the suggestion, Peter. I was going purely by what the book said. But I've learnt about POSIX compliance today because I asked. \$\endgroup\$ – Martin Nov 12 at 10:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.