VS2012 Error:不存在从“——”到“——*”的适当转换函数—已解决

源代码功能为建立并输出链表。《C程序设计》P316。

源代码如下:

#include<stdio.h>
#include<malloc.h>
#define LEN sizeof(struct Student)
struct Student
{
long num;
float score;
struct Student* next;
};
int n;
struct Student* creat()
{
struct Student* head;
struct Student* p1,*p2;
n = 0;
p1 = p2 =(struct Student*)malloc(LEN);
scanf_s("%ld,%f",&p1->num,&p1->score);
head = NULL;
while (p1 -> num!= 0)
{
n = n + 1;
if(n == 1)head = p1;
else p2 -> next = p1;
p2 = p1;
p1 = (struct Student*)malloc(LEN);
scanf_s("%ld,%f",&p1 -> num,&p1 -> score);
}
p2 -> next = NULL;
return(head);
};
void print(struct Student head )
{
struct Student* p;
printf("\nNow,These %d records are:\n",n);
p = head;
if(head != NULL)
do
{
printf("%ld %5.1f\n",p->num,p->score);
p = p->next;
} while (p != NULL);
}
void main()
{
struct Student* head;
head = creat();
print(head);
}

编译时出现如下错误:


查找后发现是head忘了加*。将void print(struct Student head )改为void print(struct Student *head ),则编译时顺利通过。


发布了22 篇原创文章 · 获赞 8 · 访问量 14万+
展开阅读全文

数据结构的疑问:不存在从 "int" 转换到 "People" 的适当构造函数?

06-26

``` #include<stdio.h> #include<iostream> #define MaxWindow 30 #define MaxProc 1 #define error 0 using namespace std; typedef struct People ElementType; struct People { int T; int P; }; typedef int Position; struct QNode { ElementType *Data; Position Front, Rear; int MaxSize; }; typedef struct QNode *Queue; Queue CreatQueue(int MaxSize) { Queue Q = (Queue)malloc(sizeof(struct QNode)); Q->Data = (ElementType *)malloc(MaxSize * sizeof(ElementType)); Q->Front = Q->Rear = 0; Q->MaxSize = MaxSize; return Q; } bool IsFull(Queue Q) { return((Q->Rear + 1) % Q->MaxSize == Q->Front); } bool AddQ(Queue Q, ElementType X) { if (IsFull(Q)) { printf("队列满\n"); return false; } else { Q->Rear = (Q->Rear + 1) % Q->MaxSize; Q->Data[Q->Rear] = X; return true; } } bool IsEmpty(Queue Q) { return(Q->Front == Q->Rear); } ElementType DeleteQ(Queue Q) { if (IsEmpty(Q)) { printf("队列空\n"); return 0; } else { Q->Front = (Q->Front + 1) % Q->MaxSize; return Q->Data[Q->Front]; } } void DestroyQueue(Queue Q) { free(Q); } double QueueingAtBank(Queue Q, int N) { struct People Next; int k; int TotalTime; int CurrentTime; int Window[MaxWindow]; int WaitTime; int WinAvail; int i, j; scanf("%d", &k); for (i = 0; i < k; i++) Window[i] = 0; TotalTime = 0; while (!IsEmpty) { WinAvail = FindNextWindow(Window, k, &WaitTime); CurrentTime += WaitTime; Next = DeleteQ(Q); if (CurrentTime >= Next.T) TotalTime += (CurrentTime - Next.T); else { WaitTime = Next.T - CurrentTime; for (j = 0; j < k; j++) { Window[j] -= WaitTime; if (Window[j] < 0) Window[j] = 0; } CurrentTime = Next.T; } Window[WinAvail] = Next.P; } return((double)TotalTime / (double)N); } int FindNextWindow(int W[], int k, int *WaitTime) { int WinAvail; int MinW = MaxProc + 1; int i; for (i = 0; i < k; i++) if (W[i] < MinW) { MinW = W[i]; WinAvail = i; } *WaitTime = MinW; for (i = 0; i < k; i++) W[i] -= MinW; return WinAvail; } int main() { int N; Queue Q; int i; ElementType X; scanf("%d", &N); Q = CreatQueue(N); for (i = 0; i < N; i++) { scanf("%d %d", &X.T, &X.P); AddQ(Q, X); } printf("Average waiting time = %.lf minute(s).\n", QueueingAtBank(Q, N)); DestroyQueue(Q); return 0; } ``` 1 IntelliSense: 不存在从 "int" 转换到 "People" 的适当构造函数 请问各位大佬我这串代码的报错是为什么呀 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览