c-在VsCode中被[-Wint转换]卡住



这是我第一次尝试在VsCode中制作c程序,我不明白为什么它一直给我这个警告:

  • 返回类型默认为"int"[-Wimplicit int]
  • 传递"DeleteListId"的参数1使指针中的整数不带强制转换[-Wint conversion]
  • 变量"Phead"设置但未使用[-Wunused但设置变量]
  • 传递"strcmp"的参数2使指针从整数变为不带强制转换[-Wint conversion]
  • 传递"strcmp"的参数2使指针从整数变为不带强制转换[-Wint conversion]

这是迄今为止的代码:

#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("nn      t++++++++++++++++++++++++++++++++++++++++++n");
printf("    tWelcome to vaccination information system n");
printf("      t++++++++++++++++++++++++++++++++++++++++++n");
printf("  tt++++++++++++++++++++++++++n");
printf("    tt  Project Main Menun");
printf("  tt++++++++++++++++++++++++++n");
printf("   tt1. Read File Menun");
printf("   tt2. Doubly Linked list Menun");
printf("   tt3. linked Queue Menu n");
printf("   tt4. Exit ");
printf("n  tt++++++++++++++++++++++++++n");
printf("nnChoice :");
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("nn   Open citizens File  n");
printf("   1-Load txt Filen");
printf("   2-Backn");
while (1)
{
printf("nnChoice :");
scanf("%d", &opn);
switch (opn)
{
case 1:
FillData();Create_List_From_File();Create_Queue_From_File();
break;
case 2:
return main();
default: printf("nnWrong choice.. nn");
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  ttFirstShottSecondShot t Vacc Date tVacc Name");
printf("n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++n");
i = 0;
while (i<FCount)
{
printf("%st%s t %s t  %d t t%d tt%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("nn  t++++++++++++++++++++++++++n");
printf("         Doubly Linked list    ");
printf("n  t++++++++++++++++++++++++++");
printf("nt 1 - Insert new entry");
printf("nt 2 - Delete By Civil ID");
printf("nt 3 - Display all ");
printf("nt 4 - Display all entries by doses");
printf("nt 5 - Backn");
printf("  t++++++++++++++++++++++++++n");
while (1)
{
printf("nnChoice : ");
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  ttFirstShottSecondShot t Vacc Date tVacc Name");
printf("n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++n");
PriFoo = head;
while (PriFoo != NULL)
{
printf("%st%s t %s t  %d t t%d tt%d %d %d t%sn", 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  ttFirstShottSecondShot t Vacc Date tVacc Name");
printf("n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++n");
PriFoo = head;
while (PriFoo != NULL)
{
if (PriFoo->FirstShot == dose)
printf("%st%s t %s t  %d t t%d tt%d %d %d t%sn", 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("nn  t++++++++++++++++++++++++++n");
printf("              Linked Queue    n");
printf("  t++++++++++++++++++++++++++");
printf("n t1- Enqueue ");
printf("n t2- Dequeue ");
printf("n t3- View  ");
printf("n t4- Backn");
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  ttFirstShottSecondShot t Vacc Date tVacc Name");
printf("n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++n");
for (QR = front; QR != NULL; QR = QR->next)
printf("%st%s t %s t  %d t t%d tt%d %d %d t%sn", 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("%st%s t %s t  %d t t%d tt%d %d %d t%sn", front->FIRSTNAME, front->LASTNAME, front->CIVILLID, front->FirstShot, 
front->SecondShot, front->Day, front->month, front->Year, front->NameVaccTaken);
free(front);
front = DelNodQ;
}
else
{
printf("%st%s t %s t  %d t t%d tt%d %d %d t%sn", front->FIRSTNAME, front->LASTNAME, front->CIVILLID, front->FirstShot,
front->SecondShot, front->Day, front->month, front->Year, front->NameVaccTaken);
free(front);
front = NULL;
rear = NULL;
}
}
int DeleteListId(int Search)

看起来您希望Search是一个字符串(const char *(。

其他错误:

  • 对无效输入递归调用main是不明智的;一个足够长的无效输入序列会导致程序堆栈溢出而崩溃。用循环重写。

  • 切勿使用gets。从不从不我不在乎你是否"相信你所有的投入";或";没有其他人会使用这个程序";。从不

  • 在类似的行中,strcpy(TokenArray[FCount].FIRSTNAME, token);:token可能长达100个字符,而目的地只能容纳20个字符。这是一个缓冲区溢出漏洞。应该检查并修复所有strcpy实例中可能存在的溢出。是的,strcpy本身很方便,但像这样的习惯是人们最终对重大安全漏洞负责的方式。

  • 在像int TxtF();这样的所有声明中:这并没有将TxtF声明为接受参数的函数,而是将其定义为接受未指定的参数的函数。(这是C++中您想要的,但C不是C++。(如果您试图用参数调用TxtF,编译器不会阻止您,但在运行时会发生未定义的行为。将其设为int TxtF(void);,并更改所有类似的实例。有关更多详细信息,请参阅C99中的func((与func(void(。

  • variable 'Phead' set but not used:你写了这个变量,但从来没有读过。那么你为什么一开始就创建它呢?也许你本想用它做点什么,但忘了。仔细重新检查此函数中的代码。

  • fillData中,如果fopen失败,您将使用file == NULL调用fclose(file)并崩溃。CCD_ 18可能想要在CCD_ 19块内。

最新更新