c - 在 C 中取消引用指针数组

标签 c arrays pointers dereference

我在这段代码中遇到问题 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/

相关文章:

c - 如何使用rand——C99版本

c++ - 如何读取多行输入?

javascript - underscore.js 根据单词数组从字符串中删除文本

c++ - 哪个更好,指向其他类的指针或从该类继承

javascript - 将基于 JIT 的 lang 编译为 Webassembly

c++ - 最大的回文产品-程序无法运行,写了解决方案但无法理解问题

c++ - 我无法正确删除 vector 中的元素

c++ - double[][] 不等于 **double 吗?

c++ - 使用 Clang 编译 DLL 时指定 DEF 文件

javascript - 组合 if else 语句(.contains?)的更简单方法