[英]Too few arguments error
我正在尝试让我的代码用来自文件的数据填充结构中的数组。
截至目前,它还没有编译,只是给出了标题中的错误。
我希望弄清楚这一点,以便我可以继续编写代码,但是最近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';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.