//main.h
#ifndef PRINTF
#define PRINTF
#include <stdio.h>
#include <limits.h>
typedef struct specifiers
{
char s;
int (*func)(char *s, int i);
} spec_t;
int print_int(int);
int _putchar(char c);
int _puts(char *s);
int main(void);
#endif
//print_int.c
int print_int(int input)
{
int tmp;
int i;
if (input == 0)
{
i = 0;
return (i);
}
tmp = (input % 10) + 48;
i = print_int(input / 10);
putchar(tmp);
i++;
return (i);
}
//main.c
#include "main.h"
#include <limits.h>
#include <stdio.h>
int main(void)
{
int test = INT_MAX;
test = print_int(test);
printf("\n%i", test);
return (test);
}
These are compiled using: gcc -Wall -Wextra -Werror -pedantic -std=gnu89 -Wno-format main.h main.c print_int.c -o test
For some reason, these files won't link at compile time. Anyone got any ideas?
I tried putting the function prototype for int print_int(int);
directly into the "main.c" file. This works, but I want all the prototypes to be inside "main.h". I don't know how to expand on this any more. Is there anything anyone can do?