Where are the arguments and return types in C exercises

I am not able to find how to start the darts problem. I can’t get info about the arguments and function etc.

Read the tests. Here at Exercism the instructions tell a story and give you a quick sketch of the problem. All the details are in the tests, you are supposed to read them, they are the specification (at least in the practice exercises.)

1 Like

How do i access these floats?

coordinate_t landing_position = { -9.0F, 9.0F };

landing_position is neither array nor pointer nor vector

coordinate_t landing_position means landing_position is a coordinate_t. However, coordinate_t is not yet defined. You need to define it. It is a type that contains two float values; that would generally be a struct which has two members, both of type float. So you need to define a new type, coordinate_t, which will be defined as a struct with two float members. Based on the name, the type represents a coordinate, so you probably want to name those members something like x and y.

Does that make sense?

what am i doing wrong here? I don’t understand

#include "darts.h"
#include <stdint.h>
#include <stdio.h>

struct coordinate_t = {
    float x,
    float y
    }

uint8_t score(landing_position) {
    printf("%d",landing_position.x);
    return 0;
}

Can you share your .h file?
Did you get an error message? Can you share it here, too?

In the meantime: There are multiple issues.

  • Did you define the type coordinate_t in the .h file?
  • The part of the code that starts with struct coordinate_t is not valid C. If you want to learn how define a struct, take a look at chapter 8: structs in Beej’s Guide to C Programming.
  • The conversion specification %d tells printf() to print an int. But landing_position.x is probably a float, right?
  • The function parameter has a name (landing_position) but no type.
1 Like

I thought %d also worked for float. I don’t understand the meaning of header file, Is it for making something like classes?

.h file:

#ifndef DARTS_H
#define DARTS_H

#endif

error:

./darts.c:5:21: error: expected identifier or '(' before '=' token
    5 | struct coordinate_t = {
      |                     ^
./darts.c:10:9: error: no previous declaration for 'score' [-Werror=missing-declarations]
   10 | uint8_t score(landing_position) {
      |         ^~~~~
./darts.c: In function 'score':
./darts.c:10:9: error: type of 'landing_position' defaults to 'int' [-Wimplicit-int]
./darts.c:11:33: error: request for member 'x' in something not a structure or union
   11 |     printf("%d",landing_position.x);
      |                                 ^
./darts.c:10:9: error: parameter 'landing_position' set but not used [-Werror=unused-but-set-parameter]
   10 | uint8_t score(landing_position) {
      |         ^~~~~
cc1: all warnings being treated as errors
./test_darts.c: In function 'test_missed_target':
./test_darts.c:14:4: error: unknown type name 'coordinate_t'
   14 |    coordinate_t landing_position = { -9.0F, 9.0F };
      |    ^~~~~~~~~~~~
./test_darts.c:14:45: error: excess elements in scalar initializer [-Werror]
   14 |    coordinate_t landing_position = { -9.0F, 9.0F };
      |                                             ^~~~
./test_darts.c:14:45: note: (near initialization for 'landing_position')
./test_darts.c:16:21: error: implicit declaration of function 'score' [-Wimplicit-function-declaration]
   16 |    uint8_t actual = score(landing_position);
      |                     ^~~~~
./test_darts.c: In function 'test_on_the_outer_circle':
./test_darts.c:22:4: error: unknown type name 'coordinate_t'
   22 |    coordinate_t landing_position = { 0.0F, 10.0F };
      |    ^~~~~~~~~~~~
./test_darts.c:22:44: error: excess elements in scalar initializer [-Werror]
   22 |    coordinate_t landing_position = { 0.0F, 10.0F };
      |                                            ^~~~~
./test_darts.c:22:44: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_on_the_middle_circle':
./test_darts.c:30:4: error: unknown type name 'coordinate_t'
   30 |    coordinate_t landing_position = { -5.0F, 0.0F };
      |    ^~~~~~~~~~~~
./test_darts.c:30:45: error: excess elements in scalar initializer [-Werror]
   30 |    coordinate_t landing_position = { -5.0F, 0.0F };
      |                                             ^~~~
./test_darts.c:30:45: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_on_the_inner_circle':
./test_darts.c:38:4: error: unknown type name 'coordinate_t'
   38 |    coordinate_t landing_position = { 0.0F, -1.0F };
      |    ^~~~~~~~~~~~
./test_darts.c:38:44: error: excess elements in scalar initializer [-Werror]
   38 |    coordinate_t landing_position = { 0.0F, -1.0F };
      |                                            ^
./test_darts.c:38:44: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_exactly_on_center':
./test_darts.c:46:4: error: unknown type name 'coordinate_t'
   46 |    coordinate_t landing_position = { 0.0F, 0.0F };
      |    ^~~~~~~~~~~~
./test_darts.c:46:44: error: excess elements in scalar initializer [-Werror]
   46 |    coordinate_t landing_position = { 0.0F, 0.0F };
      |                                            ^~~~
./test_darts.c:46:44: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_near_the_center':
./test_darts.c:54:4: error: unknown type name 'coordinate_t'
   54 |    coordinate_t landing_position = { -0.1F, -0.1F };
      |    ^~~~~~~~~~~~
./test_darts.c:54:45: error: excess elements in scalar initializer [-Werror]
   54 |    coordinate_t landing_position = { -0.1F, -0.1F };
      |                                             ^
./test_darts.c:54:45: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_just_within_the_inner_circle':
./test_darts.c:62:4: error: unknown type name 'coordinate_t'
   62 |    coordinate_t landing_position = { 0.7F, 0.7F };
      |    ^~~~~~~~~~~~
./test_darts.c:62:44: error: excess elements in scalar initializer [-Werror]
   62 |    coordinate_t landing_position = { 0.7F, 0.7F };
      |                                            ^~~~
./test_darts.c:62:44: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_just_outside_the_inner_circle':
./test_darts.c:70:4: error: unknown type name 'coordinate_t'
   70 |    coordinate_t landing_position = { 0.8F, -0.8F };
      |    ^~~~~~~~~~~~
./test_darts.c:70:44: error: excess elements in scalar initializer [-Werror]
   70 |    coordinate_t landing_position = { 0.8F, -0.8F };
      |                                            ^
./test_darts.c:70:44: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_just_within_the_middle_circle':
./test_darts.c:78:4: error: unknown type name 'coordinate_t'
   78 |    coordinate_t landing_position = { -3.5F, 3.5F };
      |    ^~~~~~~~~~~~
./test_darts.c:78:45: error: excess elements in scalar initializer [-Werror]
   78 |    coordinate_t landing_position = { -3.5F, 3.5F };
      |                                             ^~~~
./test_darts.c:78:45: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_just_outside_the_middle_circle':
./test_darts.c:86:4: error: unknown type name 'coordinate_t'
   86 |    coordinate_t landing_position = { -3.6F, -3.6F };
      |    ^~~~~~~~~~~~
./test_darts.c:86:45: error: excess elements in scalar initializer [-Werror]
   86 |    coordinate_t landing_position = { -3.6F, -3.6F };
      |                                             ^
./test_darts.c:86:45: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_just_within_the_outer_circle':
./test_darts.c:94:4: error: unknown type name 'coordinate_t'
   94 |    coordinate_t landing_position = { -7.0F, 7.0F };
      |    ^~~~~~~~~~~~
./test_darts.c:94:45: error: excess elements in scalar initializer [-Werror]
   94 |    coordinate_t landing_position = { -7.0F, 7.0F };
      |                                             ^~~~
./test_darts.c:94:45: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_just_outside_the_outer_circle':
./test_darts.c:102:4: error: unknown type name 'coordinate_t'
  102 |    coordinate_t landing_position = { 7.1F, -7.1F };
      |    ^~~~~~~~~~~~
./test_darts.c:102:44: error: excess elements in scalar initializer [-Werror]
  102 |    coordinate_t landing_position = { 7.1F, -7.1F };
      |                                            ^
./test_darts.c:102:44: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_asymmetric_position_between_the_inner_and_middle_circles':
./test_darts.c:110:4: error: unknown type name 'coordinate_t'
  110 |    coordinate_t landing_position = { -0.5F, -4.0F };
      |    ^~~~~~~~~~~~
./test_darts.c:110:45: error: excess elements in scalar initializer [-Werror]
  110 |    coordinate_t landing_position = { -0.5F, -4.0F };
      |                                             ^
./test_darts.c:110:45: note: (near initialization for 'landing_position')
cc1: all warnings being treated as errors
make: *** [makefile:37: tests.out] Error 1

I thought %d also worked for float.

No, it doesn’t.


I don’t understand the meaning of header file, Is it for making something like classes?

You can think of a .h file as an interface. It contains the type definitions and function declarations that other .h and .c files should be able to use.
The .c is is the implementation, it defines the functions and contains all the little details that make things work.
For more about the role of .h files you might want to read chapter 17 Multifile Projects in Beej’s Guide to C Programming.


In this exercise the test file test_darts.c does #include your .h file. It then uses the type coordinate_t and calls the function score like this:

static void test_missed_target(void)
{
   coordinate_t landing_position = { -9.0F, 9.0F };
   uint8_t expected = 0;
   uint8_t actual = score(landing_position);
   TEST_ASSERT_EQUAL_UINT8(expected, actual);
}

Currently you get a lot of errors because the compiler doesn’t know anything about coordinate_t or score when it compiles the tests.

So you have to define the type coordinate_t and declare the function score in the .h file.
You also have to define the function score in the .c file.

how do I define score and coordinate_t in .h? I did this

#ifndef DARTS_H
#define DARTS_H


struct coordinate_t {
    float x;
    float y;
};

uint8_t score(coordinate_t landing_position);

#endif

Did you read the link I posted (chapter 8: structs)?

That looks promising. Did you get a different error message?

There’s still an issue: When you want to use a type like struct coordinate_t without the keyword struct you have to add a typedef. For more about that see chapter 10.2.1: typedef and structs in Beej’s Guide to C Programming.

Yes now it doesn’t know what is score coordinate_t and uint8_t. I have removed the function from .c

In file included from ./darts.c:1:
./darts.h:10:1: error: unknown type name 'uint8_t'
   10 | uint8_t score(coordinate_t landing_position);
      | ^~~~~~~
./darts.h:1:1: note: 'uint8_t' is defined in header '<stdint.h>'; this is probably fixable by adding '#include <stdint.h>'
  +++ |+#include <stdint.h>
    1 | #ifndef DARTS_H
./darts.h:10:15: error: unknown type name 'coordinate_t'
   10 | uint8_t score(coordinate_t landing_position);
      |               ^~~~~~~~~~~~
In file included from ./test_darts.c:2:
./darts.h:10:15: error: unknown type name 'coordinate_t'
   10 | uint8_t score(coordinate_t landing_position);
      |               ^~~~~~~~~~~~
./test_darts.c: In function 'test_missed_target':
./test_darts.c:14:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   14 |    coordinate_t landing_position = { -9.0F, 9.0F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:14:45: error: excess elements in scalar initializer [-Werror]
   14 |    coordinate_t landing_position = { -9.0F, 9.0F };
      |                                             ^~~~
./test_darts.c:14:45: note: (near initialization for 'landing_position')
./test_darts.c:16:21: error: implicit declaration of function 'score' [-Wimplicit-function-declaration]
   16 |    uint8_t actual = score(landing_position);
      |                     ^~~~~
./test_darts.c: In function 'test_on_the_outer_circle':
./test_darts.c:22:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   22 |    coordinate_t landing_position = { 0.0F, 10.0F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:22:44: error: excess elements in scalar initializer [-Werror]
   22 |    coordinate_t landing_position = { 0.0F, 10.0F };
      |                                            ^~~~~
./test_darts.c:22:44: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_on_the_middle_circle':
./test_darts.c:30:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   30 |    coordinate_t landing_position = { -5.0F, 0.0F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:30:45: error: excess elements in scalar initializer [-Werror]
   30 |    coordinate_t landing_position = { -5.0F, 0.0F };
      |                                             ^~~~
./test_darts.c:30:45: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_on_the_inner_circle':
./test_darts.c:38:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   38 |    coordinate_t landing_position = { 0.0F, -1.0F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:38:44: error: excess elements in scalar initializer [-Werror]
   38 |    coordinate_t landing_position = { 0.0F, -1.0F };
      |                                            ^
./test_darts.c:38:44: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_exactly_on_center':
./test_darts.c:46:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   46 |    coordinate_t landing_position = { 0.0F, 0.0F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:46:44: error: excess elements in scalar initializer [-Werror]
   46 |    coordinate_t landing_position = { 0.0F, 0.0F };
      |                                            ^~~~
./test_darts.c:46:44: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_near_the_center':
./test_darts.c:54:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   54 |    coordinate_t landing_position = { -0.1F, -0.1F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:54:45: error: excess elements in scalar initializer [-Werror]
   54 |    coordinate_t landing_position = { -0.1F, -0.1F };
      |                                             ^
./test_darts.c:54:45: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_just_within_the_inner_circle':
./test_darts.c:62:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   62 |    coordinate_t landing_position = { 0.7F, 0.7F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:62:44: error: excess elements in scalar initializer [-Werror]
   62 |    coordinate_t landing_position = { 0.7F, 0.7F };
      |                                            ^~~~
./test_darts.c:62:44: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_just_outside_the_inner_circle':
./test_darts.c:70:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   70 |    coordinate_t landing_position = { 0.8F, -0.8F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:70:44: error: excess elements in scalar initializer [-Werror]
   70 |    coordinate_t landing_position = { 0.8F, -0.8F };
      |                                            ^
./test_darts.c:70:44: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_just_within_the_middle_circle':
./test_darts.c:78:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   78 |    coordinate_t landing_position = { -3.5F, 3.5F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:78:45: error: excess elements in scalar initializer [-Werror]
   78 |    coordinate_t landing_position = { -3.5F, 3.5F };
      |                                             ^~~~
./test_darts.c:78:45: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_just_outside_the_middle_circle':
./test_darts.c:86:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   86 |    coordinate_t landing_position = { -3.6F, -3.6F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:86:45: error: excess elements in scalar initializer [-Werror]
   86 |    coordinate_t landing_position = { -3.6F, -3.6F };
      |                                             ^
./test_darts.c:86:45: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_just_within_the_outer_circle':
./test_darts.c:94:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   94 |    coordinate_t landing_position = { -7.0F, 7.0F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:94:45: error: excess elements in scalar initializer [-Werror]
   94 |    coordinate_t landing_position = { -7.0F, 7.0F };
      |                                             ^~~~
./test_darts.c:94:45: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_just_outside_the_outer_circle':
./test_darts.c:102:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
  102 |    coordinate_t landing_position = { 7.1F, -7.1F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:102:44: error: excess elements in scalar initializer [-Werror]
  102 |    coordinate_t landing_position = { 7.1F, -7.1F };
      |                                            ^
./test_darts.c:102:44: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_asymmetric_position_between_the_inner_and_middle_circles':
./test_darts.c:110:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
  110 |    coordinate_t landing_position = { -0.5F, -4.0F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:110:45: error: excess elements in scalar initializer [-Werror]
  110 |    coordinate_t landing_position = { -0.5F, -4.0F };
      |                                             ^
./test_darts.c:110:45: note: (near initialization for 'landing_position')
cc1: all warnings being treated as errors
make: *** [makefile:37: tests.out] Error 1

The compiler tells you that it doesn’t know the type uint8_t.

That’s because uint8_t is not a fundamental data type.
If you want to use it you have to #include <stdint.h> (in your .h file).

The compiler tells you that it doesn’t know the type coordinate_t.

You have to add a typedef in your .h file.

okay i think coordinate_t is good

#ifndef DARTS_H
#define DARTS_H

typedef struct coordinate_t {
    float x;
    float y;
}

uint8_t score(coordinate_t landing_position);

#endif

error:

In file included from ./darts.c:1:
./darts.h:9:9: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'score'
    9 | uint8_t score(coordinate_t landing_position);
      |         ^~~~~
In file included from ./test_darts.c:2:
./darts.h:9:9: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'score'
    9 | uint8_t score(coordinate_t landing_position);
      |         ^~~~~
./test_darts.c: In function 'test_missed_target':
./test_darts.c:14:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   14 |    coordinate_t landing_position = { -9.0F, 9.0F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:14:45: error: excess elements in scalar initializer [-Werror]
   14 |    coordinate_t landing_position = { -9.0F, 9.0F };
      |                                             ^~~~
./test_darts.c:14:45: note: (near initialization for 'landing_position')
./test_darts.c:16:21: error: implicit declaration of function 'score' [-Wimplicit-function-declaration]
   16 |    uint8_t actual = score(landing_position);
      |                     ^~~~~
./test_darts.c: In function 'test_on_the_outer_circle':
./test_darts.c:22:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   22 |    coordinate_t landing_position = { 0.0F, 10.0F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:22:44: error: excess elements in scalar initializer [-Werror]
   22 |    coordinate_t landing_position = { 0.0F, 10.0F };
      |                                            ^~~~~
./test_darts.c:22:44: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_on_the_middle_circle':
./test_darts.c:30:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   30 |    coordinate_t landing_position = { -5.0F, 0.0F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:30:45: error: excess elements in scalar initializer [-Werror]
   30 |    coordinate_t landing_position = { -5.0F, 0.0F };
      |                                             ^~~~
./test_darts.c:30:45: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_on_the_inner_circle':
./test_darts.c:38:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   38 |    coordinate_t landing_position = { 0.0F, -1.0F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:38:44: error: excess elements in scalar initializer [-Werror]
   38 |    coordinate_t landing_position = { 0.0F, -1.0F };
      |                                            ^
./test_darts.c:38:44: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_exactly_on_center':
./test_darts.c:46:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   46 |    coordinate_t landing_position = { 0.0F, 0.0F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:46:44: error: excess elements in scalar initializer [-Werror]
   46 |    coordinate_t landing_position = { 0.0F, 0.0F };
      |                                            ^~~~
./test_darts.c:46:44: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_near_the_center':
./test_darts.c:54:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   54 |    coordinate_t landing_position = { -0.1F, -0.1F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:54:45: error: excess elements in scalar initializer [-Werror]
   54 |    coordinate_t landing_position = { -0.1F, -0.1F };
      |                                             ^
./test_darts.c:54:45: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_just_within_the_inner_circle':
./test_darts.c:62:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   62 |    coordinate_t landing_position = { 0.7F, 0.7F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:62:44: error: excess elements in scalar initializer [-Werror]
   62 |    coordinate_t landing_position = { 0.7F, 0.7F };
      |                                            ^~~~
./test_darts.c:62:44: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_just_outside_the_inner_circle':
./test_darts.c:70:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   70 |    coordinate_t landing_position = { 0.8F, -0.8F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:70:44: error: excess elements in scalar initializer [-Werror]
   70 |    coordinate_t landing_position = { 0.8F, -0.8F };
      |                                            ^
./test_darts.c:70:44: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_just_within_the_middle_circle':
./test_darts.c:78:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   78 |    coordinate_t landing_position = { -3.5F, 3.5F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:78:45: error: excess elements in scalar initializer [-Werror]
   78 |    coordinate_t landing_position = { -3.5F, 3.5F };
      |                                             ^~~~
./test_darts.c:78:45: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_just_outside_the_middle_circle':
./test_darts.c:86:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   86 |    coordinate_t landing_position = { -3.6F, -3.6F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:86:45: error: excess elements in scalar initializer [-Werror]
   86 |    coordinate_t landing_position = { -3.6F, -3.6F };
      |                                             ^
./test_darts.c:86:45: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_just_within_the_outer_circle':
./test_darts.c:94:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
   94 |    coordinate_t landing_position = { -7.0F, 7.0F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:94:45: error: excess elements in scalar initializer [-Werror]
   94 |    coordinate_t landing_position = { -7.0F, 7.0F };
      |                                             ^~~~
./test_darts.c:94:45: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_just_outside_the_outer_circle':
./test_darts.c:102:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
  102 |    coordinate_t landing_position = { 7.1F, -7.1F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:102:44: error: excess elements in scalar initializer [-Werror]
  102 |    coordinate_t landing_position = { 7.1F, -7.1F };
      |                                            ^
./test_darts.c:102:44: note: (near initialization for 'landing_position')
./test_darts.c: In function 'test_asymmetric_position_between_the_inner_and_middle_circles':
./test_darts.c:110:4: error: unknown type name 'coordinate_t'; use 'struct' keyword to refer to the type
  110 |    coordinate_t landing_position = { -0.5F, -4.0F };
      |    ^~~~~~~~~~~~
      |    struct 
./test_darts.c:110:45: error: excess elements in scalar initializer [-Werror]
  110 |    coordinate_t landing_position = { -0.5F, -4.0F };
      |                                             ^
./test_darts.c:110:45: note: (near initialization for 'landing_position')
cc1: all warnings being treated as errors
make: *** [makefile:37: tests.out] Error 1

Take a closer look at the definition of the struct.
There’s a semicolon (;) missing at the end.

Also, the typedef is wrong.
The example in chapter 10.2.1: typedef and structs might be helpful.

yes i did that and it gave me this error:

./darts.h:8:1: error: useless storage class specifier in empty declaration [-Werror]
    8 | };
      | ^
./darts.h:10:15: error: unknown type name 'coordinate_t'
   10 | uint8_t score(coordinate_t landing_position);
      |               ^~~~~~~~~~~~
cc1: all warnings being treated as errors
In file included from ./test_darts.c:2:
./darts.h:8:1: error: useless storage class specifier in empty declaration [-Werror]
    8 | };
      | ^

I guess you modified your solution and got this new error message, right? Can you post your solution again?

okay yes the typedef was wrong. edit: typo haha

#ifndef DARTS_H
#define DARTS_H
#include <stdint.h>

typedef struct coordinate_t {
    float x;
    float y;
} coordinate_t;

uint8_t score(coordinate_t landing_position);

#endif

error:

/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccIOdAEG.o: in function `test_missed_target':
/mnt/exercism-iteration/./test_darts.c:16:(.text+0x3e): undefined reference to `score'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccIOdAEG.o: in function `test_on_the_outer_circle':
/mnt/exercism-iteration/./test_darts.c:24:(.text+0x94): undefined reference to `score'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccIOdAEG.o: in function `test_on_the_middle_circle':
/mnt/exercism-iteration/./test_darts.c:32:(.text+0xea): undefined reference to `score'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccIOdAEG.o: in function `test_on_the_inner_circle':
/mnt/exercism-iteration/./test_darts.c:40:(.text+0x140): undefined reference to `score'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccIOdAEG.o: in function `test_exactly_on_center':
/mnt/exercism-iteration/./test_darts.c:48:(.text+0x192): undefined reference to `score'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccIOdAEG.o:/mnt/exercism-iteration/./test_darts.c:56: more undefined references to `score' follow
collect2: error: ld returned 1 exit status
make: *** [makefile:37: tests.out] Error 1

Why animal? I think you want coordinate_t instead.

Now the compiler tells you that the function score is declared but not defined anywhere.
You have to define it in the .c file.

okay its working

#include "darts.h"
#include <stdint.h>
#include <stdio.h>


uint8_t score(coordinate_t landing_position) {
    printf("%f",landing_position.x);
    return 0;
}
#ifndef DARTS_H
#define DARTS_H
#include <stdint.h>

typedef struct coordinate_t {
    float x;
    float y;
} coordinate_t;

uint8_t score(coordinate_t landing_position);

#endif

1 Like