Revision as of 06:28, 11 July 2012 by Rhea (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 Maze_construct(char* frame);
void Maze_traverse(Maze m);
void Maze_destruct(Maze m);

  1. endif
    /*main.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

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;

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
makeclean


Back to ECE264, Spring 2011, Prof. Lu

Alumni Liaison

Ph.D. on Applied Mathematics in Aug 2007. Involved on applications of image super-resolution to electron microscopy

Francisco Blanco-Silva