Scheduler.c 我正在爲類進行調度程序,並且我被這個錯誤卡住了。它表示不兼容的類型從'int'類型鍵入'Ev'。我很困惑這可能意味着什麼。不兼容類型從類型'int'在類型50中鍵入'Ev'
int main()
{
Ev *event;
int numEvents=0;
int option;
int x;
int y;
char menu[]="1 - Insert a new event\n2 - Display all events\n3 - Now?\n4 - Delete expired\n0 - Exit\nPlease select an option: ";
event = malloc(sizeof(Ev) *numEvents);
CopynumEvents(&numEvents);
for (y=0; y<numEvents; y++)
{
event = realloc(event, sizeof(Ev) * (y + 1));
**MY ERROR SEEMS TO BE AROUND THIS AREA**
event[y]=CopyfromFile(numEvents,y);
}
option = MenuOption(menu);
while(1)
{
switch(option)
{
case(1):
event = realloc(event, sizeof(Ev) * (numEvents + 1));
numEvents++;
event[numEvents - 1]=InsertEvent();
ArrangeEvents(event,numEvents);
CopytoFile(numEvents, event);
option = MenuOption(menu);
break;
case(2):
if (numEvents!=0)
{
for (x=0; x<numEvents; x++)
{
DisplayEvent(event[x]);
}
}
else
{
printf("No event in scheduler\n");
}
option = MenuOption(menu);
break;
case(3):
ActiveEvents(event, numEvents);
option = MenuOption(menu);
break;
case(4):
DeleteExpired(event, &numEvents);
CopytoFile(numEvents, event);
option = MenuOption(menu);
break;
case(0):
free(event);
exit(1);
break;
}
}
}
int MenuOption(char *prompt)
{
char buffer[100];
int option;
do
{
printf("%s", prompt);
/* Get a line of up to 100 characters */
fgets(buffer, sizeof(buffer), stdin);
/* Remove any \n we may have input */
if(strlen(buffer) > 0)
buffer[strlen(buffer)-1] = '\0';
sscanf(buffer, "%d", &option);
}while(option!=1 && option!=2 && option!=3 && option!=4 && option!=0);
return option;
}
struct Event InsertEvent()
{
struct Event E1;
printf("What is the event: ");
InputEventname(E1.name, sizeof(E1.name));
E1.date = InputDate("Event date: ");
E1.start = InputTime("Start time: ",E1.date);
do
{
E1.end = InputTime("End time: ",E1.date);
}while(E1.end<=E1.start);
return E1;
}
void InputEventname(char *str, int max)
{
char buffer[100];
/* Get a line of up to 100 characters */
fgets(buffer, sizeof(buffer), stdin);
/* Remove any \n we may have input */
if(strlen(buffer) > 0)
buffer[strlen(buffer)-1] = '\0';
/* Copy up to max characters to our string */
strncpy(str, buffer, max);
str[max-1] = '\0';
}
time_t InputTime(char *prompt, time_t date)
{
char buffer[100];
char *result;
struct tm time;
time = *localtime(&date);
do
{
printf("%s", prompt);
/* Get a line of up to 100 characters */
fgets(buffer, sizeof(buffer), stdin);
/* Remove any \n we may have input */
if(strlen(buffer) > 0)
buffer[strlen(buffer)-1] = '\0';
result = strptime(buffer, "%I:%M%p", &time);
} while(result == NULL);
return mktime(&time);
}
time_t InputDate(char *prompt)
{
char buffer[100];
char *result;
struct tm date;
do
{
printf("%s", prompt);
/* Get a line of up to 100 characters */
fgets(buffer, sizeof(buffer), stdin);
/* Remove any \n we may have input */
if(strlen(buffer) > 0)
buffer[strlen(buffer)-1] = '\0';
result = strptime(buffer, "%m/%d/%Y", &date);
} while(result == NULL);
/* Convert to time_t format */
date.tm_min = 0;
date.tm_hour = 0;
date.tm_sec = 0;
date.tm_isdst = 1;
return mktime(&date);
}
這是我的標題。我相信我做了這部分的權利
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <string.h>
#define __USE_XOPEN
#include <time.h>
#include "scheduler.h"
/*
* This is my scheduling program!!
*/
/* Our possible scheduling states */
#define NewEvent 1
#define AllEvents 2
#define Now 3
#define Expired 4
#define Exit 0
#ifndef DISPLAY_H
#define DISPLAY_H
typedef struct Event
{
char name[50];
time_t date;
time_t start;
time_t end;
int y;
}Ev;
int MenuOption(char *prompt);
struct Event InsertEvent();
void InputEventname(char *str, int max);
time_t InputDate(char *prompt);
time_t InputTime(char *prompt, time_t date);
void DisplayEvent(Ev event);
#endif
'CopyfromFile'?我們可以研究它嗎? –
這意味着你正試圖將Ev類型的變量設置爲一個int變量。機會是你的CopyFromFile方法返回一個int,而不是Ev,所以'event [y] = CopyfromFile(numEvents,y);'試圖設置事件[y](應該是類型「Ev」)爲值鍵入「int」 – DerStrom8
行50是錯誤號是 – user3574840