gpt4 book ai didi

c - 参数太少错误

转载 作者:行者123 更新时间:2023-11-30 16:59:56 24 4
gpt4 key购买 nike

我正在尝试让我的代码用文件中的数据填充结构内的数组。

到目前为止,它还没有编译,只是给出了标题中的错误。

我希望弄清楚这一点,这样我就可以继续编写代码,但过去 4 个小时对我来说没有任何作用......

#include <stdio.h>
#include <stdlib.h>

#define MAX 100

FILE *fp;
FILE *fpIn;
FILE *fpOut;

typedef struct {
char first[7];
char initial[1];
char last[9];
char street[16];
char city[11];
char state[2];
char zip[5];
int age;
char sex[1];
int tenure;
double salary;
} workers;

void readFile();
void strsub (char buf[], char sub[], int start, int end);

int main()
{

if (!(fpIn = fopen("payfile.txt", "r")))
{
printf("payfile.txt could not be opened for input.");
exit(1);
}
if (!(fpOut = fopen("csis.txt", "w")))
{
printf("csis.txt could not be opened for output.");
exit(1);
}

return 0;
}

void readFile()
{
char buf[MAX];
while(!feof(fpIn))
{
fgets(buf, MAX, fpIn);
strsub(buf, workers[i].first, 0, 6);
strsub(buf, workers[i].initial, 8, 8);
strsub(buf, workers[i].last, 10, 18);
strsub(buf, workers[i].street, 20, 35);
strsub(buf, workers[i].city, 37, 47);
strsub(buf, workers[i].state, 49, 50);
strsub(buf, workers[i].zip, 52, 56);
strsub(buf, workers[i].age, 58, 59);
strsub(buf, workers[i].sex, 61, 61);
strsub(buf, workers[i].tenure, 63, 63);
strsub(buf, workers[i].salary, 65, 70);
}
}

void strsub (char buf[], char sub[], int start, int end)
{
int i, j;

for (j=0, i=start; i <= end; i++, j++)
{
sub[j] = buf[i];
}
sub[j] = '\0';
}

最佳答案

我已修复以便您的程序可以编译,但它仍然存在问题。我不得不注释掉类型不匹配,但至少可以编译,以便您有一些工作要做。

#include <stdio.h>

#include <stdio.h>
#include <stdlib.h>

#define MAX 100

FILE *fp;
FILE *fpIn;
FILE *fpOut;

typedef struct {
char first[7];
char initial[1];
char last[9];
char street[16];
char city[11];
char state[2];
char zip[5];
int age;
char sex[1];
int tenure;
double salary;
} workers;

void readFile();
void strsub (char buf[], char sub[], int start, int end);

int main()
{

if (!(fpIn = fopen("payfile.txt", "r")))
{
printf("payfile.txt could not be opened for input.");
exit(1);
}
if (!(fpOut = fopen("csis.txt", "w")))
{
printf("csis.txt could not be opened for output.");
exit(1);
}

return 0;
}
workers array[8];
void readFile()
{
int i =0;
char buf[MAX];
while(!feof(fpIn))
{
fgets(buf, MAX, fpIn);
strsub(buf, array[i].first, 0, 6);
strsub(buf, array[i].initial, 8, 8);
strsub(buf, array[i].last, 10, 18);
strsub(buf, array[i].street, 20, 35);
strsub(buf, array[i].city, 37, 47);
strsub(buf, array[i].state, 49, 50);
strsub(buf, array[i].zip, 52, 56);
strsub(buf, array[i].age, 58, 59);
strsub(buf, array[i].sex, 61, 61);
strsub(buf, array[i].tenure, 63, 63);
//strsub(buf, array[i].salary, 65, 70);
}
}

void strsub (char buf[], char sub[], int start, int end)
{
int i, j;

for (j=0, i=start; i <= end; i++, j++)
{
sub[j] = buf[i];
}
sub[j] = '\0';
}

关于c - 参数太少错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37902902/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com