Разделение С кода на несколько файлов - C (СИ)
Формулировка задачи:
Нужно разделить исходный код на 5 частей.
Пока вот что получилось
stack.h
stack.c
reverse.h
reverse.c
program1.c
Начал компилировать через командную строку,stack.obj получился, а вот с reverse проблемы. Выдает вот такую ошибку
#include <stdio.h>
#define MAXVAL 100
int sp=0;
char val[MAXVAL];
void push(char c)
{
if (sp < MAXVAL)
val[sp++] = c;
else
printf("error: stack full, can’t push %g\n", c);
}
char pop(void)
{
if (sp > 0)
return val[--sp];
else
return 0;
}
int reverse(void)
{
int counter=0;
char c;
// first push all the values on the stack
c = getchar();
while (c!='\n')
{
counter++;
push(c);
c = getchar();
}
// then take them off the stack in opposite order
while ((c=pop()) != 0)
{
putchar(c);
}
return counter;
}
void main(void)
{
printf("\n%d\n",reverse());
getchar();
}#define MAXVAL 100 int sp=0; char val[MAXVAL]; void push(char c); void pop();
#include "stack.h"
void push(char c)
{
if (sp < MAXVAL)
val[sp++] = c;
else
printf("error: stack full, can’t push %g\n", c);
}
char pop(void)
{
if (sp > 0)
return val[--sp];
else
return 0;
}#include "stack.h" int reverse();
#include "stack.h"
#include "reverse.h"
int reverse(void)
{
int counter=0;
char c;
// first push all the values on the stack
c = getchar();
while (c!='\n')
{
counter++;
push(c);
c = getchar();
}
// then take them off the stack in opposite order
while ((c=pop()) != 0)
{
putchar(c);
}
return counter;
}#include <stdio.h>
#include "stack.h"
#include "revesre.h"
void main(void)
{
printf("\n%d\n",reverse());
getchar();
}Решение задачи: «Разделение С кода на несколько файлов»
textual
Листинг программы
int sp = 0;