I have a recursive function for printed out some information from a Linked list node.
Code:
void generateItemReport(ItemType* currentItem) {
char token[MAX_DESC_LEN + 1];
int n, count = 0;
char data[MAX_DESC_LEN + 1];
if (currentItem != NULL) {
generateItemReport(currentItem->nextItem);
strcpy(data, currentItem->itemDescription);
printf("Item ID\t: %-6s\n", currentItem->itemID);
printf("Item Name\t: %-26s\n", currentItem->itemName);
printf("Prices\t: $%d.%.2d $%d.%.2d $%d.%.2d\n",
currentItem->prices[0].dollars, currentItem->prices[0].cents,
currentItem->prices[1].dollars, currentItem->prices[1].cents,
currentItem->prices[2].dollars, currentItem->prices[2].cents);
printf("Description :\n");
while(sscanf(data, "%[^ ]%n", token, &n ) > 0) {
count += n + 1;
if( count < CONSOLE_MAX_LEN)
printf("%s ", token);
else {
printf("\n");
count = 0;
}
data += n;
if( data[0] == '\0')
break;
data = data + 1;
}
getchar();
}
}
Seems sound to me but i get an error message at two places.
data += n; // invalid operands to binary + (have 'char[251]' and 'int')
data = data + 1; // incompatable types when assigning to type 'char[251]' from type 'char *'