grade-school: fix header declarions
This commit is contained in:
@@ -16,10 +16,9 @@ void clear_roster()
|
|||||||
/* testing program expects bool here, but I prefer to return students count,
|
/* testing program expects bool here, but I prefer to return students count,
|
||||||
* it makes more sense for me.
|
* it makes more sense for me.
|
||||||
*/
|
*/
|
||||||
int add_student(char *s, uint8_t g)
|
int add_student(const char *s, const uint8_t g)
|
||||||
{
|
{
|
||||||
int c=roster.count;
|
int c=roster.count, i;
|
||||||
int i;
|
|
||||||
|
|
||||||
if (c >= MAX_STUDENTS)
|
if (c >= MAX_STUDENTS)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -37,12 +36,12 @@ int add_student(char *s, uint8_t g)
|
|||||||
/* to avoid this everytime, we could build up one roster per grade while
|
/* to avoid this everytime, we could build up one roster per grade while
|
||||||
* adding students, but really overkill here.
|
* adding students, but really overkill here.
|
||||||
*/
|
*/
|
||||||
roster_t get_grade(uint8_t g)
|
roster_t get_grade(const uint8_t g)
|
||||||
{
|
{
|
||||||
roster_t r;
|
roster_t r;
|
||||||
unsigned i, j=0;
|
unsigned i, j;
|
||||||
|
|
||||||
for (i=0; i<roster.count && GRADE(i)<=g; ++i) {
|
for (i=0, j=0; i<roster.count && GRADE(i)<=g; ++i) {
|
||||||
if (GRADE(i)==g)
|
if (GRADE(i)==g)
|
||||||
r.students[j++]=STD(i);
|
r.students[j++]=STD(i);
|
||||||
}
|
}
|
||||||
|
@@ -3,14 +3,12 @@
|
|||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
//#include <stdbool.h>
|
|
||||||
|
|
||||||
#define MAX_NAME_LENGTH 20
|
|
||||||
#define MAX_STUDENTS 20
|
#define MAX_STUDENTS 20
|
||||||
|
|
||||||
typedef struct student_s {
|
typedef struct student_s {
|
||||||
uint8_t grade;
|
uint8_t grade;
|
||||||
char *name;
|
const char *name;
|
||||||
} student_t;
|
} student_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -18,10 +16,10 @@ typedef struct {
|
|||||||
student_t students[MAX_STUDENTS];
|
student_t students[MAX_STUDENTS];
|
||||||
} roster_t;
|
} roster_t;
|
||||||
|
|
||||||
void clear_roster();
|
void clear_roster(void);
|
||||||
int add_student(char *, uint8_t);
|
int add_student(const char *student, const uint8_t grade);
|
||||||
roster_t get_grade(uint8_t);
|
roster_t get_grade(const uint8_t grade);
|
||||||
roster_t get_roster();
|
roster_t get_roster(void);
|
||||||
|
|
||||||
/* See GNUmakefile below for explanation
|
/* See GNUmakefile below for explanation
|
||||||
* https://github.com/braoult/exercism/blob/master/c/templates/GNUmakefile
|
* https://github.com/braoult/exercism/blob/master/c/templates/GNUmakefile
|
||||||
|
Reference in New Issue
Block a user