how can i fix this errors?
Error LNK2019 unresolved external symbol _fscnaf referenced in function _main Project44
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol _Error_msg referenced in function _main Project44
Error LNK2019 unresolved external symbol _CreateProducts referenced in function _main Project44
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
typedef struct Item
{
char* ProductName;
int Price;
int Quantity;
struct Node* next;
}Item;
typedef struct kitchen
{
Item* head;
Item* tail;
int size;
}kitchen, * P_kit;
typedef struct table
{
Item* table_order;
struct Node* head;
}table;
///void Error_Msg(char*);///
void Delete(kitchen);
int checkItemfordelete(kitchen*, Item*);
void CreateProducts(P_kit, FILE*);
void AddItems(P_kit, char, int);
void OrderItem(kitchen*, int, int, char, table*);
void RemoveItem(int, table*);
void RemoveTable(int, table*);
int main()
{
kitchen kit;
table table_n[50];
int temp, Option = 0, t_quant, t_table, i;
char t_product[50];
FILE* manot = fopen("Manot.txt", "r");
if (manot == NULL)
{
Error_msg("Something gone wrong with opening the file!\n");
}
FILE* instructions = fopen("Instructions.txt", "r");
if (instructions == NULL)
{
Error_msg("Something gone wrong with opening the file!\n");
}
for (i = 0; i < 50; i++)
{
table_n[i].head = NULL;
}
printf("Press 1 to create the kitchen.\n");
while (fscnaf(instructions, "%d", &Option) != 1)
{
printf("Press 1 to create the kitchen.\n");
}
CreateProducts(&kit, manot);
printf("The kitchen was created successfuly!\n");
fclose(manot);
while (fscanf(instructions, "%d", &Option) == 1)
{
switch (Option)
{
case 2:
fscanf(instructions, "%s %d", t_product, &t_quant);
AddItems(&kit, t_product, t_quant);
break;
case 3:
fscanf(instructions, "%d %s %d", &t_table, t_product, &t_quant);
OrderItem(&kit, t_table, t_quant, t_product, &table_n[50]);
break;
case 4:
fscanf(instructions, "%d", &t_table);
RemoveItem(t_table, &table_n[50]);
break;
case 5:
fscanf(instructions, "%d", &t_table);
RemoveItem(t_table, &table_n[50]);
break;
}
}
printf("Finish!\n");
fclose(instructions);
return 0;
}
void Error_Msg(char* msg)//Error msg for open files.
{
printf("\n%s", msg);
exit(1); /*Exit() closes any open files in the program*/
}
void Delete(P_kit kit)
{
Item* temp;
while (kit->head != NULL)
{
temp = kit->head;
kit->head = (kit->head)->next;
free(temp);
}
}
int checkItemfordelete(kitchen* kit, Item* temp)
{
Item* temp1 = kit->head;
while (temp)
{
if (strcmp(temp1->ProductName, temp->ProductName) == 0)
{
temp1 = kit->head;
kit->head = (kit->head)->next;
free(temp->ProductName);
free(temp);
return 0;
}
temp = temp->next;
}
return 1;
}
void CreateProduct(kitchen* kit, FILE* f)//Function creates class of students and returnes it.
{
char buffer[99];
int len, i = 1, flag = 0;
Item* temp;
kit->size = 0;
temp = (Item*)malloc(sizeof(Item));
if (temp == NULL)
{
printf("Memory allocation error!\n");
exit(1);
}
while (fscanf(f, "%s%d%d", buffer, &(temp->Price), &(temp->Quantity)) != EOF)//Takes the data of every student
{
len = strlen(buffer) + 1;
temp->ProductName = (char*)malloc(len * sizeof(char));//Gets the memory for names with enough place
if (temp->ProductName == NULL)
{
free(temp->ProductName);
}
strcpy(temp->ProductName, buffer);//Puts the names into array
if (temp->Price < 0)
{
printf("The price can't be negative!\n");
free(temp);
}
if (temp->Quantity < 0)
{
printf("The quantity can't be negative!\n");
free(temp);
}
if (kit->size == 0)
{
kit->head = temp;
kit->tail = kit->head;
kit->size++;
}
if (kit->size > 0)
{
flag = checkItemfordelete(kit, temp);
}
if (kit->size > 0 && flag == 0)
{
kit->tail->next = temp;
kit->tail = kit->tail->next;
kit->size++;
}
temp = (Item*)malloc(sizeof(Item));
if (temp == NULL)
{
printf("Memory allocation error!\n");
exit(1);
}
}
}
void AddItems(P_kit kit, char added, int num)//Function adds the quantity to the kitchen kit. If there is no such item or the quantity in < 0 - prints error msg.
{
Item* temp = kit->head;
int flag = 0;
if (num < 0)//Checks if the quantity is positive.
{
printf("Error! The quantity for adding must be positive!\n");
return;
}
while (temp != NULL)
{
if (strcmp(added, temp->ProductName) == 0)//Checks the name of the item inside the list.
{
temp->Quantity = temp->Quantity + num;//Adds the quantity to the item.
flag = 1;
break;
}
else temp = temp->next;
}
if (flag == 0)//Didn't find inputed item.
{
printf("Error! There is no such item in the kitchen!\n");
}
}
void OrderItem(kitchen* kit, int table_num, int item_quant, char order, table table_arr[50])
{
Item* temp = kit->head;
Item* temp_ord;
int flag = 0, len;
if (table_num <= 0 && table_num > 50)//Checks if the table number exists.
{
printf("Error! There is no such number of table in our restaurant!\n");
return;
}
while (temp != NULL && flag != 1)//Checks if meal name does exist.
{
if (strcmp(order, temp->ProductName) == 0)//Checks the name of the item inside the list.
{
flag = 1;
}
else temp = temp->next;
}
if (flag == 0)//If not exist.
{
printf("Error! There is no such meal in our kitchen!\n");
return;
}
if (item_quant < 0 && temp->Quantity - item_quant < 0)
{
printf("Error! There number is wrong!\n");
return;
}
temp_ord = (Item*)malloc(sizeof(Item));
len = strlen(order) + 1;
temp_ord->ProductName = (char*)malloc(len * sizeof(char));//Gets the memory for names with enough place
if (temp_ord->ProductName == NULL)
{
free(temp_ord->ProductName);
}
strcpy(temp_ord->ProductName, order);//Puts the names into array
temp_ord->Price = temp->Price;
temp_ord->Quantity = item_quant;
temp_ord->next = table_arr[table_num].head;
table_arr[table_num].head = temp_ord;
temp->Quantity = temp->Quantity - item_quant;
}
void RemoveItem(int tab, table* table_n[50])
{
Item* temp;
temp = table_n[tab]->head;
if (table_n[tab]->head == NULL)
{
printf("There is no order in this table!\n");
}
else
{
temp = table_n[tab]->head;
table_n[tab]->head = temp->next;
printf("The canceled dish is :%s\n", temp->ProductName);
printf("The amount have been canceled is :%d", temp->Quantity);
free(temp->ProductName);
free(temp);
}
}
void RemoveTable(int tab, table* table_arr[50])
{
Item* temp, * temp_to_free;
float tip = 0, bill = 0, price;
temp = table_arr[tab]->head;
if (tab > 50 || tab < 1)
{
printf("The table number is not exist! \n");
return;
}
if (temp == NULL)
{
printf("The table's bill was already closed or there was no order!!\n");
return;
}
while (temp != NULL)
{
price = (temp->Price) * (temp->Quantity);
bill = +price;
printf("Check:\n:Table No.%d\n\n", tab);
printf("Quantity\t");
printf("Product\t");
printf("Price\n");
printf("%d\t", temp->Quantity);
printf("%s\t", temp->ProductName);
printf("%.2f\n", price);
temp_to_free = table_arr[tab]->head;
table_arr[tab]->head = temp->next;
temp = temp->next;
free(temp_to_free->ProductName);
free(temp_to_free);
}
printf("The bill is :%.2f\n\n", bill);
tip = +(bill * 15) / 100;
printf("The tip is :%.2f\n\n", tip);
bill += tip;
printf("The total price is: %.2f\n", bill);
}
<
Error LNK2019 unresolved external symbol _CreateProducts referenced in function _main Project44
Error LNK2019 unresolved external symbol _Error_msg referenced in function _main Project44 >
how can i fix this error?
_fscnaf
should be_fscanf
so if you getunresolved external symbol _fscnaf referenced
I guess you've misspelledfscanf
in your code somewhere - but it's not in the code you've shown. Please show a minimal reproducible example.while (fscnaf(instructions, "%d", &Option) != 1)
is an obvious typo.void Error_Msg(char*);
as in the commented out prototype orError_msg
as in the places you use it. Once you uncomment the prototype and fixe the case issues you need to work through each warning or error, read the message, and correct the issue. It will help if you don't typedef pointers. If you aren't getting a ton of warnings you need to turn the warning level up in your compiler. godbolt.org/z/3fdzsG9WG