Structs(Sample Code):
- ifndef MAZE_H
- define MAZE_H
- include <stdio.h>
typedef struct { int startRow,startCol; int exitRow, exitCol; int numRow,numCol;
int** cells; }Maze;
Maze Maze_construct(char* frame); void Maze_traverse(Maze m); void Maze_destruct(Maze m);
- endif
In "maze.c":
/*maze.c*/
- include "maze.h"
- include <stdio.h>
Maze Maze_contruct(char* fname) { FIEL* fMaze; fMaze = fopen(fname); if(fMaze ==0) { //error } while(!feof(fMaze)) { //stuff } }
- include <stdio.h> main.c
- include "maze.h"
int main() { Maze m; if(argc<2) { //error } m = Mazeconstruct(argv[1]); Maze_traverse(m) Maze_destruct(m) return 0; }
gcc -c maze.c need malloc gcc maze.o main.o -o implicitly link c library
m.cells = malloc (sizeof(char*) * numRow); for
How to define the Struct:
typedef struct { int x; int y; int z; }Vector;
Vector Vector_construct(int a int b int c); Vector Vector_add(vector v1 vector v2);
Vector Vector_construct(int a, int b, int c) Pbecor v;
Commands needed in Makefile or just in terminal to properly compile.
gcc -c main.c gcc -c maze.c gcc main.o maze.o -o ipa1 ./ipa1 maze1 <-- means the current folder's ipa1 file. current directory make file for each directory makeclean