int linkedlistReponseAsBuffer(linkedlistelement * firstelement, char ** buffer, FILE * log) { int numberofelements = 0; int currentelement = 0; int openingfound = 0; int i = 0; int j = 0; char * localbuffer = NULL; linkedlistelement * localelement = firstelement; while ( localelement != NULL ) { numberofelements++; /* DEBUG FILE */ fprintf(log, "Scanning for number of elements: %s\n", localelement->data); /* DEBUG FILE */ localelement = localelement->next; } /* DEBUG FILE */ fprintf(log, "Number of elements found: %i\n", numberofelements); fflush(log); /* DEBUG FILE */ localelement = firstelement; localbuffer = new char[(numberofelements*sizeof(localelement->data))]; /* DEBUG FILE */ fprintf(log, "Created the new local buffer successfully.\n"); fflush(log); /* DEBUG FILE */ while ( localelement != NULL ) { for (i = 0; (unsigned)i < strlen(localelement->data) ; i++) { if ( (openingfound == 0) && (localelement->data[i] == '(') ) { openingfound = i; /* DEBUG FILE */ fprintf(log, "Opening found at position: %i.\n", openingfound); fflush(log); /* DEBUG FILE */ continue; } if ( (openingfound != 0) && (localelement->data[i] == ')') ) { i = strlen(localelement->data); /* DEBUG FILE */ fprintf(log, "End found at position %i of element %i.\n", i, currentelement); fflush(log); /* DEBUG FILE */ localelement = NULL; continue; } if ( (openingfound != 0) && (currentelement == 0)) { localbuffer[i-(openingfound+1)] = localelement->data[i]; /* DEBUG FILE */ fprintf(log, "Copying data %c at %i -> Position %i, data written %c\n", localelement->data[i], i, (i-(openingfound+1)), local$ fflush(log); /* DEBUG FILE */ continue; } if ( (openingfound != 0) && (currentelement != 0)) { localbuffer[j+i] = localelement->data[i]; /* DEBUG FILE */ fprintf(log, "*Copying data %c at %i -> Position %i, data written %c\n", localelement->data[i], i, (j+i), localbuffer[j+i]); fflush(log); /* DEBUG FILE */ continue; } } j = i-(openingfound+1); currentelement++; localelement = localelement->next; } /* DEBUG FILE */ fprintf(log, "The new local buffer data: %s.\n", localbuffer); fflush(log); /* DEBUG FILE */ delete[] localbuffer; return 0; }