Function frequency: Difference between revisions

Made program actually print top ten functions/macros by marking each struct functionInfo when printing it.
(Added first attempt at a C version.)
(Made program actually print top ten functions/macros by marking each struct functionInfo when printing it.)
Line 103:
char* name;
int timesCalled;
char marked;
};
void addToList(struct functionInfo** list, struct functionInfo toAdd, \
Line 136 ⟶ 137:
memcpy((*list)[0].name, toAdd.name, strlen(toAdd.name));
(*list)[0].timesCalled = 1;
(*list)[i0].timesCalled)marked = 0;
*numElements = 1;
}
Line 166 ⟶ 168:
memcpy((*list)[*numElements].name, toAdd.name, strlen(toAdd.name));
(*list)[*numElements].timesCalled = 1;
(*list)[*numElements].marked = 0;
(*numElements)++;
}
Line 171 ⟶ 174:
}
void printList(struct functionInfo** list, size_t numElements) {
forchar (int imaxSet = 0;i<numElements;i++) {
size_t maxIndex = 0;
printf("\"%s\" called %d times.\n", (*list)[i].name, \
for (int i = 0;i<10;i++) {
(*list)[i].timesCalled);
maxSet = 0;
for (int j = 0;j<numElements;j++) {
if (!maxSet || (*list)[j].timesCalled > (*list)[maxIndex].timesCalled) {
if (!(*list)[j].marked) {
maxSet = 1;
maxIndex = j;
}
}
}
(*list)[maxIndex].marked = 1;
printf("\"%s\"() called %d times.\n", (*list)[imaxIndex].name, \
(*list)[maxIndex].timesCalled);
}
}