I'm trying to make a program where i use linked list to store data of cakes, currently i am making an add cake function. This function will validate a few things. I want to validate so that the input code must not be the same as an existing code in the linked list. Here is the function :
struct cookie
{
char code[10], name[100];
int stock, price;
struct cookie *next;
};
int validateCode(struct cookie *test, char kode[10]){
int check;
int flag;
while(test != NULL){
check = strcmp(test->code, kode);
if(check == 0){
flag = 0;
}
else{
flag = 1;
}
test = test->next;
}
if(flag == 1){
printf("%s already exists in the linked list", kode);
}
return flag;
}
Here is the output: Output
I tried to change the while condition into something like:
- test->next != NULL
- test->code != NULL
and none of it works for me
ok turns out im stupid lol i found the solution, thank you for the comments, very useful tips