我在这段代码中遇到问题
printf("\nIn Func: %s", (*article[ctr]).artname);
我使用 Code:Blocks 并收到错误“对 WinMain@16 的 undefined reference ”,文章是一个指针数组,我不应该通过取消引用来访问它吗?我也尝试过 -> 但没有成功。
我可以违背某些规定吗?
感谢您的帮助,我添加了下面的完整代码。
头文件:
#ifndef _LAGER_H
#define _LAGER_H
#define MAXCHAR 40
#define lagerdateiname "lager.dat"
struct artikel_t
{
int artnr;
char artname[MAXCHAR];
float preis;
int bestand;
int min;
};
#endif
代码文件:
#include "lagdat.h"
#include <string.h>
#include <stdio.h>
int bestellMenge(struct artikel_t *article[], int len)
{
int errCode;
int retVal;
int ctr = 0;
struct artikel_t art;
unsigned int writtenArticles = 0;
unsigned int leftArticles = 0;
errCode = openLager();
if(!errCode)
{
int readOK;
while(!(readOK = readNext(&art)) && ctr < len)
{
if(art.bestand < art.min)
{
article[ctr] = &art;
ctr++;
writtenArticles++;
printf("\nIn Func: %s", (*article[ctr]).artname);
}
}
}
}
最佳答案
您必须在 ctr++ 之前打印,如下所示。当前您正在尝试指向您未填写的文章对象
article[ctr] = &art;
printf("\nIn Func: %s", (*article[ctr]).artname);
ctr++;
writtenArticles++;
关于c - 在 C 中取消引用指针数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42887475/