This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
OT - Question about error messages
- From: Michael Sullivan <michael at espersunited dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Sun, 11 Nov 2007 11:51:02 -0600
- Subject: OT - Question about error messages
I hope this is the right place to ask this. I have a short program
consisting of two files:
michael@camille ourrpg $ nl character.h
1 /*character.h - Header file for the character struct and
function prototypes*/
2 #ifndef __CHARACTER_H__
3 #define __CHARACTER_H__
4
5 typedef struct
6 {
7 char *name;
8 unsigned long currentHP, maxHP, currentMP, maxMP;
9 } character;
10
11 void printStats(character* c);
12 character createCharacter(char* name, long maxHP, long maxMP)
13 character scanCharacter(void);
14
15 #endif
michael@camille ourrpg $ nl character.c
1 /*character.c - Description of a basic character*/
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include "character.h"
6
7 void printStats(character* c)
8 {
9 printf("This character's name is %s.\n", c->name);
10 printf("%s's max HP is %ld.\n", c->name, c->maxHP);
11 printf("%s's max MP is %ld.\n\n", c->name, c->maxMP);
12 }
13
14 character createCharacter(char* name, long maxHP, long maxMP)
15 {
16 character c;
17 c.name = name;
18 c.maxHP = maxHP;
19 c.maxMP = maxMP;
20
21 c.currentHP = maxHP;
22 c.currentMP = maxMP;
23 return c;
24 }
25
26 character scanCharacter(void)
27 {
28 char name[8];
29 long maxHP, maxMP;
30
31 printf("What is this character's name? ");
32 scanf("%s", &name);
33
34 do
35 {
36 printf("What is %s's max HP? ", name);
37 scanf("%ld", &maxHP);
38 maxHP = atol(maxHP);
39 if (maxHP <= 0)
40 printf("Max HP must be a positive number greater than
zero. Let's try this again...\n\n");
41 }
42 while (maxHP <= 0);
43
44
45
46 do
47 {
48 printf("What is %s's max MP? ", name);
49 scanf("%ld", &maxMP);
50 maxMP = atol(maxMP);
51 if (maxMP <= 0)
52 printf("Max MP must be a positive number greater than
zero. Let's try this again...\n\n");
53 }
54 while (maxMP <= 0);
55
56 printf("\n\n");
57
58 return createCharacter(name, maxHP, maxMP);
59 }
60
61
62 int main()
63 {
64 character char1[4];
65
66 int i;
67 for (i = 0; i < 4; i++)
68 {
69 char1[i] = scanCharacter();
70 printStats(&char1[i]);
71 }
72
73 return 0;
74 }
When I compile it, I get this:
character.c: In function 'createCharacter':
character.c:8: error: expected '=', ',', ';', 'asm' or '__attribute__'
before '{' token
character.c:15: error: expected '=', ',', ';', 'asm' or '__attribute__'
before '{' token
character.c:27: error: expected '=', ',', ';', 'asm' or '__attribute__'
before '{' token
character.c:63: error: expected '=', ',', ';', 'asm' or '__attribute__'
before '{' token
character.c:74: error: old-style parameter declarations in prototyped
function definition
character.c:74: error: expected '{' at end of input
make: *** [character] Error 1
I have no idea what those errors mean. Can anyone help me, or else
direct me to a website that provides explanations for what gcc error
messages mean? Thank you.