Table of Contents

Lab 05 - Structs and enums

Reading strings

Help function for reading longer strings with spaces into a char*

char* getInput()
{
	char* string = NULL;
	int strlen = 0;
	while(1)
	{
		char character;
		scanf("%c", &character);
		if(character == 10)
		{
			return string;
		}
		strlen++;
		string = realloc(string, strlen);
		string[strlen-1] = character;
	}
}

Strings revision

Enums and structs

Doxygen

Examples

/// number of color channels
static const int numChannels = 3;

/// A macro that returns the maximum of \a a and \a b.
#define MAX(a,b) (((a)>(b))?(a):(b))

/// Enum for area fill modes. Passed to sglAreaMode() function.
enum sglEAreaMode {
  SGL_POINT = 0,	///< Draw only vertices
  SGL_LINE  = 1,	///< Draw only borders of graphics elements (lines)
  SGL_FILL  = 2 	///< Draw filled elements, default
};

/// Create a new drawing context.
/**
  Create a new drawing context for the drawing window with dimensions width x height of
  RGB pixels. Allocates additional internal structures for the context (including the
  depth buffer).

  \param[in] width   Desired canvas width.
  \param[in] height  Desired canvas height.
  \return Unique identifier of the drawing context.

  ERRORS:
   - SGL_OUT_OF_MEMORY ... not enough memory
   - SGL_OUT_OF_RESOURCES ... too many contexts
     (Implementation dependent. At least 32 must be provided, though.)
*/
int sglCreateContext(int width, int height);