This is my first attempt at making a c program in VsCode and I couldn't understand why it keeps giving me this warning:
- return type defaults to 'int' [-Wimplicit-int]
- passing argument 1 of 'DeleteListId' makes integer from pointer without a cast [-Wint-conversion]
- variable 'Phead' set but not used [-Wunused-but-set-variable]
- passing argument 2 of 'strcmp' makes pointer from integer without a cast [-Wint-conversion]
- passing argument 2 of 'strcmp' makes pointer from integer without a cast [-Wint-conversion]
This is the code so far:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct STRUCT
{
char FIRSTNAME[20];
char LASTNAME[20];
char CIVILLID[13];
int Day, month, Year;
int FirstShot;
int SecondShot;
char NameVaccTaken[20];
};
struct Node
{
char FIRSTNAME[20];
char LASTNAME[20];
char CIVILLID[13];
int Day, month, Year;
int FirstShot;
int SecondShot;
char NameVaccTaken[20];
struct Node *next;
struct Node *prev;
};
struct QNode
{
char FIRSTNAME[20];
char LASTNAME[20];
char CIVILLID[13];
int Day, month, Year;
int FirstShot;
int SecondShot;
char NameVaccTaken[20];
struct QNode *next;
};
struct Node *NeNode = NULL;
struct Node *Phead = NULL;
struct Node *head, *Phead;
struct QNode *QR = NULL;
struct QNode *front, *rear;
struct QNode *DelNodQ, *FooQ, *Foo, *Q;
void EnqueueCiti();
void DequeueCiti();
void Print_Citi();
int main();
int TxtF();
int Menu_Linked_List();
int Menu_Linked_Queue();
void FillData();
int FCount = 0;
struct STRUCT TokenArray[50];
void Create_List_From_File();
void Create_Queue_From_File();
void Insert_New_Citz_List();
void PrintListData();
void PrintListDataDS(int dose);
int DeleteListId(int Search);
void create_DLL();
int main()
{
int C = 0;
system("cls");
printf("\n\n \t++++++++++++++++++++++++++++++++++++++++++\n");
printf(" \tWelcome to vaccination information system \n");
printf(" \t++++++++++++++++++++++++++++++++++++++++++\n");
printf(" \t\t++++++++++++++++++++++++++\n");
printf(" \t\t Project Main Menu\n");
printf(" \t\t++++++++++++++++++++++++++\n");
printf(" \t\t1. Read File Menu\n");
printf(" \t\t2. Doubly Linked list Menu\n");
printf(" \t\t3. linked Queue Menu \n");
printf(" \t\t4. Exit ");
printf("\n \t\t++++++++++++++++++++++++++\n");
printf("\n\nChoice :");
scanf("%d", &C);
switch (C)
{
case 1:
printf("\n");
return TxtF();
case 2:
printf("\n");
return Menu_Linked_List();
case 3:
printf("\n");
return Menu_Linked_Queue();
case 4:
return 0;
default:
printf("Invalid \n");
return main();
}
return main();
}
int TxtF()
{
int opn;
system("cls");
printf("\n\n Open citizens File \n");
printf(" 1-Load txt File\n");
printf(" 2-Back\n");
while (1)
{
printf("\n\nChoice :");
scanf("%d", &opn);
switch (opn)
{
case 1:
FillData();Create_List_From_File();Create_Queue_From_File();
break;
case 2:
return main();
default: printf("\n\nWrong choice.. \n\n");
break;
}
}
return 0;
}
void FillData()
{
FILE * file;
char FrLine[999];
int i, Col;
char* token;
file = fopen("ProjText.txt", "r");
FCount = 0;
if (file != NULL)
{
while (fgets(FrLine, 100, file))
{
i = 0;
Col = 0;
token = strtok(FrLine, ",");
while (token != NULL)
{
Col++;
if (Col == 1)
{
strcpy(TokenArray[FCount].FIRSTNAME, token);
}
else if (Col == 2)
{
strcpy(TokenArray[FCount].LASTNAME, token);
}
else if (Col == 3)
{
strcpy(TokenArray[FCount].CIVILLID, token);
}
else if (Col == 4)
{
TokenArray[FCount].FirstShot = atoi(token);
}
else if (Col == 5)
{
TokenArray[FCount].SecondShot = atoi(token);
}
else if (Col == 6)
{
TokenArray[FCount].Day = atoi(token);
}
else if (Col == 7)
{
TokenArray[FCount].month = atoi(token);
}
else if (Col == 8)
{
TokenArray[FCount].Year = atoi(token);
}
else if (Col == 9)
{
strcpy(TokenArray[FCount].NameVaccTaken, token);
}
token = strtok(NULL, ",");
}
FCount++;
}
}
fclose(file);
printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf(" NAME \tCIVID \t\tFirstShot\tSecondShot \t Vacc Date \tVacc Name");
printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
i = 0;
while (i<FCount)
{
printf("%s\t%s \t %s \t %d \t \t%d \t\t%d %d %d \t%s",
TokenArray[i].FIRSTNAME, TokenArray[i].LASTNAME, TokenArray[i].CIVILLID,
TokenArray[i].FirstShot, TokenArray[i].SecondShot, TokenArray[i].Day,
TokenArray[i].month, TokenArray[i].Year, TokenArray[i].NameVaccTaken);
i++;
}
printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
}
void Create_List_From_File()
{
struct Node *current;
head = current = NULL;
int i;
for (i = 0; i<FCount; i++)
{
struct Node *Node = (struct Node*) malloc(sizeof(struct Node));
strcpy(Node->FIRSTNAME, TokenArray[i].FIRSTNAME);
strcpy(Node->LASTNAME, TokenArray[i].LASTNAME);
strcpy(Node->CIVILLID, TokenArray[i].CIVILLID);
Node->FirstShot = TokenArray[i].FirstShot;
Node->SecondShot = TokenArray[i].SecondShot;
Node->Day = TokenArray[i].Day;
Node->month = TokenArray[i].month;
Node->Year = TokenArray[i].Year;
strcpy(Node->NameVaccTaken, TokenArray[i].NameVaccTaken);
Node->next = NULL;
if (head == NULL)
head = Node;
else
{
Node->next = head;
Node->next->prev = Node;
head = Node;
}
}
}
void Create_Queue_From_File()
{
int i;
for (i = 0; i<FCount; i++)
{
FooQ = (struct QNode *)malloc(1 * sizeof(struct QNode));
strcpy(FooQ->FIRSTNAME, TokenArray[i].FIRSTNAME);
strcpy(FooQ->LASTNAME, TokenArray[i].LASTNAME);
strcpy(FooQ->CIVILLID, TokenArray[i].CIVILLID);
FooQ->FirstShot = TokenArray[i].FirstShot;
FooQ->SecondShot = TokenArray[i].SecondShot;
FooQ->Day = TokenArray[i].Day;
FooQ->month = TokenArray[i].month;
FooQ->Year = TokenArray[i].Year;
strcpy(FooQ->NameVaccTaken, TokenArray[i].NameVaccTaken);
if (rear == NULL)
{
rear = (struct QNode *)malloc(1 * sizeof(struct QNode));
strcpy(rear->FIRSTNAME, FooQ->FIRSTNAME);
strcpy(rear->LASTNAME, FooQ->LASTNAME);
strcpy(rear->CIVILLID, FooQ->CIVILLID);
rear->FirstShot = FooQ->FirstShot;
rear->SecondShot = FooQ->SecondShot;
rear->Day = FooQ->Day;
rear->month = FooQ->month;
rear->Year = FooQ->Year;
strcpy(rear->NameVaccTaken, FooQ->NameVaccTaken);
rear->next = NULL;
front = rear;
}
else
{
rear->next = FooQ;
FooQ->next = NULL;
rear = FooQ;
}
}
}
int Menu_Linked_List()
{
int ch;
char Search[12];
int check;
int dose;
system("cls");
printf("\n\n \t++++++++++++++++++++++++++\n");
printf(" Doubly Linked list ");
printf("\n \t++++++++++++++++++++++++++");
printf("\n\t 1 - Insert new entry");
printf("\n\t 2 - Delete By Civil ID");
printf("\n\t 3 - Display all ");
printf("\n\t 4 - Display all entries by doses");
printf("\n\t 5 - Back\n");
printf(" \t++++++++++++++++++++++++++\n");
while (1)
{
printf("\n\nChoice : ");
scanf("%d", &ch);
switch (ch)
{
case 1: Insert_New_Citz_List();
break;
case 2:getchar();
printf("\nEnter Civil ID : ");
gets(Search);
check = DeleteListId(Search);
if (check)
printf("%s was deleted \n", Search);
else
printf("%s Not found \n", Search);
break;
case 3:PrintListData();
break;
case 4:printf("\nEnter number of doses to check the entries : ");
scanf("%d", &dose);
PrintListDataDS(dose);
break;
case 5:return main();
default: printf("\n Wrong choice...");
}
}
return 0;
}
void create_DLL()
{
NeNode = (struct Node *)malloc(1 * sizeof(struct Node));
NeNode->prev = NULL;
NeNode->next = NULL;
getchar();
printf("First name : ");
gets(NeNode->FIRSTNAME);
printf("Last name : ");
gets(NeNode->LASTNAME);
printf("Civil ID : ");
gets(NeNode->CIVILLID);
printf("Number of doses taken : ");
scanf("%d", &NeNode->FirstShot);
printf("Number of doses to be taken : ");
scanf("%d", &NeNode->SecondShot);
printf("Next vaccination Date : ");
scanf("%d%d%d", &NeNode->Day, &NeNode->month, &NeNode->Year);
getchar();
printf("vaccination name : ");
gets(NeNode->NameVaccTaken);
}
void Insert_New_Citz_List()
{
struct Node *Phead = head;
struct Node *CUR;
create_DLL();
if (head == NULL)
{
head = NeNode;
Phead = head->next;
}
else
{
CUR = head;
while (CUR->next != NULL)
{
CUR = CUR->next;
}
CUR->next = NeNode;
NeNode->prev = CUR;
}
}
int DeleteListId(int Search)
{
struct Node *prev, *cur;
int CIVILLIDChechk = 0;
while (head != NULL && strcmp(head->CIVILLID, Search) == 0)
{
prev = head;
head = head->next;
free(prev);
CIVILLIDChechk = 1;
}
prev = NULL;
cur = head;
while (cur != NULL)
{
if (strcmp(cur->CIVILLID, Search) == 0)
{
if (prev != NULL)
{
prev->next = cur->next;
}
free(cur);
cur = prev->next;
CIVILLIDChechk = 1;
}
else
{
prev = cur;
cur = cur->next;
}
}
return CIVILLIDChechk;
}
void PrintListData()
{
struct Node *PriFoo = head;
if (head == NULL)
{
printf("List is empty.. \n");
return;
}
printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf(" NAME \tCIVID \t\tFirstShot\tSecondShot \t Vacc Date \tVacc Name");
printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
PriFoo = head;
while (PriFoo != NULL)
{
printf("%s\t%s \t %s \t %d \t \t%d \t\t%d %d %d \t%s\n", PriFoo->FIRSTNAME, PriFoo->LASTNAME, PriFoo->CIVILLID, PriFoo->FirstShot, PriFoo->SecondShot, PriFoo->Day, PriFoo->month, PriFoo->Year,
PriFoo->NameVaccTaken);
PriFoo = PriFoo->next;
}
printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
}
void PrintListDataDS(int dose)
{
struct Node *PriFoo = head;
if (head == NULL)
{
printf("List is empty.. \n");
return;
}
printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf(" NAME \tCIVID \t\tFirstShot\tSecondShot \t Vacc Date \tVacc Name");
printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
PriFoo = head;
while (PriFoo != NULL)
{
if (PriFoo->FirstShot == dose)
printf("%s\t%s \t %s \t %d \t \t%d \t\t%d %d %d \t%s\n", PriFoo->FIRSTNAME, PriFoo->LASTNAME, PriFoo->CIVILLID, PriFoo->FirstShot, PriFoo->SecondShot, PriFoo->Day, PriFoo->month, PriFoo->Year, PriFoo->NameVaccTaken);
PriFoo = PriFoo->next;
}
printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
}
int Menu_Linked_Queue()
{
int choice;
system("cls");
printf("\n\n \t++++++++++++++++++++++++++\n");
printf(" Linked Queue \n");
printf(" \t++++++++++++++++++++++++++");
printf("\n \t1- Enqueue ");
printf("\n \t2- Dequeue ");
printf("\n \t3- View ");
printf("\n \t4- Back\n");
printf(" \t++++++++++++++++++++++++++\n");
while (1)
{
printf("\nChoice : ");
scanf("%d", &choice);
switch (choice)
{
case 1:
EnqueueCiti();
break;
case 2:
DequeueCiti();
break;
case 3:
Print_Citi();
break;
case 4:
return main();
default:printf("Wrong choice..\n");break;
}
}
return 0;
}
void EnqueueCiti()
{
Foo = (struct QNode *)malloc(1 * sizeof(struct QNode));
getchar();
printf("First name : ");
gets(Foo->FIRSTNAME);
printf("Last name : ");
gets(Foo->LASTNAME);
printf("Civil ID : ");
gets(Foo->CIVILLID);
printf("Number of doses taken : ");
scanf("%d", &Foo->FirstShot);
printf("Number of doses to be taken : ");
scanf("%d", &Foo->SecondShot);
printf("Next vaccination Date : ");
scanf("%d%d%d", &Foo->Day, &Foo->month, &Foo->Year);
getchar();
printf("vaccination name : ");
gets(Foo->NameVaccTaken);
rear->next = Foo;
Foo->next = NULL;
rear = Foo;
}
void Print_Citi()
{
if ((front == NULL) && (rear == NULL))
{
printf("Queue is empty to display .");
return;
}
printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf(" NAME \tCIVID \t\tFirstShot\tSecondShot \t Vacc Date \tVacc Name");
printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
for (QR = front; QR != NULL; QR = QR->next)
printf("%s\t%s \t %s \t %d \t \t%d \t\t%d %d %d \t%s\n", QR->FIRSTNAME, QR->LASTNAME, QR->CIVILLID, QR->FirstShot, QR->SecondShot, QR->Day, QR->month, QR->Year
, QR->NameVaccTaken);
printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
}
void DequeueCiti()
{
DelNodQ = front;
if (DelNodQ == NULL)
{
printf("Queue is empty to display .");
return;
}
else
if (DelNodQ->next != NULL)
{
DelNodQ = DelNodQ->next;
printf("%s\t%s \t %s \t %d \t \t%d \t\t%d %d %d \t%s\n", front->FIRSTNAME, front->LASTNAME, front->CIVILLID, front->FirstShot,
front->SecondShot, front->Day, front->month, front->Year, front->NameVaccTaken);
free(front);
front = DelNodQ;
}
else
{
printf("%s\t%s \t %s \t %d \t \t%d \t\t%d %d %d \t%s\n", front->FIRSTNAME, front->LASTNAME, front->CIVILLID, front->FirstShot,
front->SecondShot, front->Day, front->month, front->Year, front->NameVaccTaken);
free(front);
front = NULL;
rear = NULL;
}
}