0
#include <stdio.h>

void skip(char *msg)
{
    puts(msg+6);
}

char *msg_from_amy = "Don't call me";
skip(msg_from_amy);

The above code, which is an example from the book Head First C, doesn't seem to work on my Xcode. It gives the errors: 1) Type specifier missing, defaults to 'int' 2) A parameter list without types is only allowed in a function definition

Help!

1 Answers1

2

This is normal, in C you can't put instruction outside a function.

If you read this book, http://www.mosaic-industries.com/embedded-systems/_media/c-ide-software-development/learning-c-programming-language/head-first-c-o-reilly-david-grifffiths-dawn-griffiths.pdf. Notice that they put their examples inside a main(); function.

#include <stdio.h>

void skip(char const *msg)
{
    puts(msg + 6);
}

int main(void) {
    char const *msg_from_amy = "Don't call me"; // should be const by the way
    skip(msg_from_amy); // This is an instruction
}
Stargateur
  • 24,473
  • 8
  • 65
  • 91
  • Thank you! that did the trick! But what does the const mean? As in what instructions does it give to the computer? – QuantumDust Jun 03 '17 at 16:19
  • @QuantumDust You will learn this after in your book, but the question is available [here](https://stackoverflow.com/questions/4486326/does-const-just-mean-read-only-or-something-more). If this answer fix your problem consider to validate it, so other people can know that this question is "solved" for you, [tour]. – Stargateur Jun 03 '17 at 16:27