我正在尝试将int传递给结构体。我必须验证它,类指令说我必须通过函数运行它。
以下是错误消息:
C2664: 'int get_id(char)' : cannot convert argument 1 from 'char [80]' to 'char'
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <cstring>
#include <exception>
//functions called
int get_id(char);
//structs
struct fileinfo
{
int id;
char name[20];
char state[5];
char dis_code;
float balance;
char due_date[40];
};
//why is it void?
int main(void)
{
fileinfo info[80];
int ct = 0;
char more = 'y';
char buff[80];
while (more == 'y')
{
printf("ID: ");
gets_s(buff);
info[ct].id = get_id(buff);
printf("this is ID: %i", info[ct].id);
printf("Do you want to enter another? ");
gets_s(buff);
more = buff[0];
}
system("pause");
}//end main
int get_id(char buf[])
{
int id;
char buffer[85];
bool check = false;
id = atoi(buf);
while (check == false)
{
if (id > 998)
{
printf("\n This ID number is too large, please re-enter: ");
gets_s(buffer);
id = atoi(buffer);
check = false;
}
else
{
check = true;
}
}
return id;
}