Datasheet
API in C
229
}
/********************************************************************
* 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);
// update iLength
stBlock->iLength = iNewLength;
DEBUG ? printf("addSentenceToBlock stBlock->iLength=%d\n", stBlock->iLength) : 0;
}
/********************************************************************
* Initialize a new sentence
********************************************************************/
void initializeSentence(struct Sentence *stSentence)
{
DEBUG ? printf("initializeSentence\n") : 0;










