(New page: Structs(Sample Code): <br> #ifndef MAZE_H<br>#define MAZE_H<br>#include <stdio.h> typedef struct<br>{<br>     int startRow,startCol;<br>   &nbs...)
 
 
Line 1: Line 1:
Structs(Sample Code): <br>  
+
[[Category:ECE264]] [[Category:Programming]] [[Category:C]]
 +
[[ECE264]]: Structs(Sample Code): <br>  
  
 
#ifndef MAZE_H<br>#define MAZE_H<br>#include &lt;stdio.h&gt;  
 
#ifndef MAZE_H<br>#define MAZE_H<br>#include &lt;stdio.h&gt;  
Line 30: Line 31:
  
 
gcc -c main.c <br>gcc -c maze.c<br>gcc main.o maze.o -o ipa1<br>./ipa1 maze1 &lt;--- ./ refers to current folder<br>current directory<br>make file for each directory<br>makeclean<br>
 
gcc -c main.c <br>gcc -c maze.c<br>gcc main.o maze.o -o ipa1<br>./ipa1 maze1 &lt;--- ./ refers to current folder<br>current directory<br>make file for each directory<br>makeclean<br>
 +
----
 +
[[2011_Spring_ECE_264_Lu|Back to ECE264, Spring 2011, Prof. Lu]]

Latest revision as of 06:28, 11 July 2012

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

EISL lab graduate

Mu Qiao