-2

I'm quite to programming and I don't uderstand why my program doesn't build. I don't know where exactly is the problem. To me it seems it should work. These are mostly examples i've found on the internet.

There's some code: Main:

    #include <stdlib.h>
#include <stdio.h>
#include "mod.h"

int main() {
   push(*s, 15);
   push(*s, 4);
   push(*s, 18);
   printf("%d",s->data[0]);
   system("PAUSE");
   return 0
}

Mod.c :

#define DEBUG 0
#include<stdio.h>
#include"mod.h"

//------------------------------------------------------------------------------
void push(struct Stack *s, int value)
{
  if (s->size >= MAX_DATA - 1)
  {
    #if DEBUG
      printf("no space.\n");
    #endif
  }
  else
  {
    s->data[s->size] = value;
    s->size++;
    #if DEBUG
      printf("added.\n");
    #endif
  }
}

//------------------------------------------------------------------------------
int pop(struct Stack *s)
{
  if (s->size > 0)
  {
    #if DEBUG
      printf("poped.\n");
    #endif
    return s->data[s->size] = 0;
  } else {
    s->data[s->size] = 0;
    s->size--;
  }

}

Mod.h :

#include <stdio.h>
#include <stdlib.h>
#ifndef MOD_H_INCLUDED
#define MOD_H_INCLUDED

#define MAX_DATA 30

typedef struct Stack {
  int data[MAX_DATA];
  int size;
} Stack;

// This function adds element to the end of the structure.
void push(struct Stack *s, int value);

// This function removes element from the end of the structure.
int pop(struct Stack *s);
//int pop(struct Stack *s)

#endif // MOD_H_INCLUDED

Any suggestions why it doesn't build?

Additional data,Additional data,Additional data,Additional data,

user3529236
  • 107
  • 2
  • 9
  • Please don't post live-code examples on Stack Overflow. Instead, re-write a self-containing and reduced code example from scratch that reproduces exactly the problem you want to ask about. Everything else is too broad. Also restrain from debugging requests and personal tutoring requests here on Stack Overflow. All you need to do is to formulate a concrete programming question, that's your entry-card. – Engineer2021 May 13 '14 at 11:48
  • 4
    First of all, if you post a question about compiler errors, then you should include those errors, complete an unedited, in the question. Second of all, in the `main` function there is no variable `s` declared anywhere. – Some programmer dude May 13 '14 at 11:48

1 Answers1

1

You need to declare a variable of type Stack.

#include <stdlib.h>
#include <stdio.h>
#include "mod.h"

//Pagrindinis kodas
int main() {
   Stack *s = calloc(sizeof(Stack), 1);  // calloc allocates memory and sets all bits to 0.
   push(s, 15);  // No * needed here. s is already a Stack* and the function expects a Stack*
   push(s, 4);
   push(s, 18);
   printf("%d",s->data[0]);
   system("PAUSE");
   return 0
}

There may be more errors, but this should fix the compilation problems for Main.

Klas Lindbäck
  • 33,105
  • 5
  • 57
  • 82