ECE264: Structs(Sample Code):

  1. ifndef MAZE_H
    #define MAZE_H
    #include <stdio.h>

typedef struct
     int startRow,startCol;
     int exitRow, exitCol;
     int numRow,numCol;

     int** cells;

Maze Maze_construct(char* frame);
void Maze_traverse(Maze m);
void Maze_destruct(Maze m);

  1. endif

#include "maze.h"
#include <stdio.h>
Maze Maze_contruct(char* fname)
FIEL* fMaze;
fMaze = fopen(fname);
if(fMaze ==0)

#include <stdio.h> main.c
#include "maze.h"
int main()
     Maze m;
     m = Mazeconstruct(argv[1]);
     return 0;

gcc -c maze.c need malloc
gcc maze.o main.o -o
implicitly link c library

m.cells = malloc (sizeof(char*) * numRow);

typedef struct
     int x;
     int y;
     int z;

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;

By defining a struct with 3 variables inside of it x,y, and z can not be named as antthing but they must be int values.

Needed to compile correctly with multiple files:

gcc -c main.c
gcc -c maze.c
gcc main.o maze.o -o ipa1
./ipa1 maze1 <--- ./ refers to current folder
current directory
make file for each directory

Back to ECE264, Spring 2011, Prof. Lu

Alumni Liaison

Have a piece of advice for Purdue students? Share it through Rhea!

Alumni Liaison