Datasheet
API in C using winsock
70
/********************************************************************
* Print a block.
* Output a Block with printf.
********************************************************************/
void printBlock(struct Block *stBlock)
{
int i;
DEBUG ? printf("printBlock\n") : 0;
DEBUG ? printf("block iLength = %d\n", stBlock->iLength) : 0;
for (i=0; i<stBlock->iLength; i++)
{
printSentence(stBlock->stSentence[i]);
}
}
/********************************************************************
* Add a sentence to a block
* Allocate memory and add a sentence to a Block.
********************************************************************/
void addSentenceToBlock(struct Block *stBlock, struct Sentence *stSentence)
{
int iNewLength;
iNewLength = stBlock->iLength + 1;
DEBUG ? printf("addSentenceToBlock iNewLength=%d\n", iNewLength) : 0;
// allocate mem for the new Sentence position
if (stBlock->iLength == 0)
{
stBlock->stSentence = malloc(1 * sizeof stBlock->stSentence);
}
else
{
stBlock->stSentence = realloc(stBlock->stSentence, iNewLength * sizeof stBlock->stSentence + 1);
}
// allocate mem for the full sentence struct
stBlock->stSentence[stBlock->iLength] = malloc(sizeof *stSentence);
// copy actual sentence struct to the block position
memcpy(stBlock->stSentence[stBlock->iLength], stSentence, sizeof *stSentence);










