Ok, I originally thought the problem was with the threads but now i suspect sscanf, though i have no clue as to why, maybe someone can shed some light on the highlighted lines and the output below:
Code:
Code:
typedef struct sItem {
struct sItem *nextItem;
struct sItem *prevItem;
char *symbol;
int value;
} stockItem;
stockItem *stockList = NULL;
int main (int argc, char *argv[]){
stockItem *stock;
char userInput[128];
char first[64];
int value;
while (1){
printf ("Enter> ");
if (fgets (userInput, sizeof(userInput), stdin) == NULL){
exit (0);
}
stock = stockList;
if (stock!= NULL){printf("\nSTOCK1:%s %d\n",stock->symbol,stock->value);}
if (sscanf(userInput, "%s %d", first, &value) == 2){
if (stock!= NULL){printf("\nSTOCK2:%s %d\n",stock->symbol,stock->value);}
insertStock(stock, first, value);
}
stock = stockList;
while (stock != NULL){
printf("\n%s %d\n", stock->symbol, stock->value);
stock = stock->nextItem;
}
}
}
OUTPUT:
Enter > A 1
A 1
Enter > B 2
STOCK1:A 1
STOCK2:B 1
B 1
Enter > C 3
STOCK1:B 1
STOCK2:C 1
C 1
C 3
Enter > ctrl+D
Does anyone know why the value of stockList->symbol changes after sscanf???