# Thread: Errors in this algorithm

1. ## Errors in this algorithm

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 *'

2. You should never try to increment the base pointer to an array... You can crash the program's stack or cause free() to fail when using malloc().

Code:
```char Data[MAX_DESC_LEN + 1] = {0};
char *pData = Data;

// interveining code...

// increment pointer
pData++;```

3. Thank you for this. Not only does it help. But it has given me an "A HA" moment.

4. No worries... it was a lesson learned the hard way.