Click here to Skip to main content
15,907,687 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionNeed to draw something on CListCtrl - how to do it ? Pin
Yanshof4-May-07 4:36
Yanshof4-May-07 4:36 
QuestionRe: Need to draw something on CListCtrl - how to do it ? Pin
Maximilien4-May-07 4:59
Maximilien4-May-07 4:59 
AnswerRe: Need to draw something on CListCtrl - how to do it ? Pin
Yanshof4-May-07 5:10
Yanshof4-May-07 5:10 
AnswerRe: Need to draw something on CListCtrl - how to do it ? Pin
Michael Dunn4-May-07 6:27
sitebuilderMichael Dunn4-May-07 6:27 
GeneralRe: Need to draw something on CListCtrl - how to do it ? Pin
Yanshof4-May-07 6:41
Yanshof4-May-07 6:41 
AnswerSomeone please can help me with this one ... ? Pin
Yanshof4-May-07 23:37
Yanshof4-May-07 23:37 
QuestionHow to add Event sink messages to a view? Pin
Arris744-May-07 3:37
Arris744-May-07 3:37 
QuestionFIFO, C programming Pin
C_Zealot4-May-07 3:33
C_Zealot4-May-07 3:33 
Hi all:

I have been writing a FIFO structure, but ran into a problem, it seems to me that my FIFO structure is not properly built at all.

Below is my code: (it complies with no errors or warning.)

struct _wordTable *first = NULL, *end = NULL, *current = NULL;
int number_of_word = 0; /*A global variable to indicate how many words 'addWord' function
has been added to the table.*/

void addWord(char *wordPtr)
{
/*wordSize is declared to store the length of a word.*/
int wordSize = 0, loop = 0;
struct _wordTable *working_ptr = NULL;

/*Allocate memory for new pointers.*/
working_ptr = malloc(sizeof(struct _wordTable));
if (working_ptr == NULL){
fprintf(stderr, "Out of memory.\n");
free(working_ptr);
return;
}
working_ptr->word = malloc(1);
if (working_ptr->word == NULL){
fprintf(stderr, "Out of memory.\n");
free(working_ptr->word);
free(working_ptr);
return;
}

/*Measure the length of the input string.*/
wordSize = strlen(wordPtr);
/*Trying to find a match by linearly going through the list, if one is found,
return to the caller funciton after increasing the count by 1.*/

/*If the word is already on the FIFO structure, increases the word count by 1 and return to main().*/
if (number_of_word > 0)
for (working_ptr = first; working_ptr != end; working_ptr = working_ptr->next) {
if (strcmp(wordPtr, working_ptr->word) == 0) {
/*Here is where my program will crush.*/
working_ptr->count++;
return;
}
}
}

/*If the word is a new one, add it to the FIFO structure.*/
working_ptr->count = 1; /*Add one to the count after its initialzation.*/
realloc(working_ptr->word, wordSize);
strncpy(working_ptr->word, wordPtr, wordSize);
working_ptr->word[wordSize] = '\0';
number_of_word++; /*A new word.*/

/*Now link them together in a FIFO fashion.*/
if (first == NULL) {
first = working_ptr;
current = first;
}
current->next = working_ptr;
working_ptr->next = end;
}



Any help is appreciated.
QuestionRe: FIFO, C programming Pin
David Crow4-May-07 3:54
David Crow4-May-07 3:54 
AnswerRe: FIFO, C programming Pin
Mark Salsbery4-May-07 5:40
Mark Salsbery4-May-07 5:40 
AnswerRe: FIFO, C programming Pin
toxcct4-May-07 9:45
toxcct4-May-07 9:45 
JokeRe: FIFO, C programming Pin
Moak4-May-07 10:41
Moak4-May-07 10:41 
GeneralRe: FIFO, C programming Pin
toxcct4-May-07 10:47
toxcct4-May-07 10:47 
GeneralRe: FIFO, C programming Pin
Mark Salsbery4-May-07 10:58
Mark Salsbery4-May-07 10:58 
JokeRe: FIFO, C programming Pin
toxcct4-May-07 11:01
toxcct4-May-07 11:01 
GeneralRe: FIFO, C programming Pin
Mark Salsbery4-May-07 11:11
Mark Salsbery4-May-07 11:11 
GeneralRe: FIFO, C programming Pin
toxcct4-May-07 11:15
toxcct4-May-07 11:15 
GeneralRe: FIFO, C programming Pin
Mark Salsbery4-May-07 11:17
Mark Salsbery4-May-07 11:17 
GeneralRe: FIFO, C programming Pin
toxcct4-May-07 11:20
toxcct4-May-07 11:20 
GeneralRe: FIFO, C programming Pin
Mark Salsbery4-May-07 11:24
Mark Salsbery4-May-07 11:24 
GeneralRe: FIFO, C programming Pin
Moak4-May-07 11:40
Moak4-May-07 11:40 
AnswerRe: FIFO, C programming Pin
Paul Conrad4-May-07 13:49
professionalPaul Conrad4-May-07 13:49 
Questionautomation class Pin
prithaa4-May-07 3:19
prithaa4-May-07 3:19 
AnswerRe: automation class Pin
David Crow4-May-07 4:11
David Crow4-May-07 4:11 
QuestionThemed control, difference between TABP_TABITEM and TABP_TABITEMBOTHEDGE? Pin
Moak4-May-07 2:41
Moak4-May-07 2:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.