atoiとatof変換を使用して文字列をint型とfloat型に変換するレコードを作成しています。しかし、コンパイラは私にこのエラーを与えています: "[エラー]は、 'char * gets(char *)'に引数 '1'の 'int *'を 'char *'に変換できません。 コードは次のとおりです。atoiとatofからのデータ変換
int main()
{
int ch_id[25];
float ch_gp[25];
struct Data
{
char name[25];
char Fname[25];
int idno;
float Gpa;
};
Data emp;
cout<<"Enter name:";
gets(emp.name);
cout<<"Enter fathers's name:";
gets(emp.Fname);
cout<<"Enter Id number:";
gets(ch_id);
emp.idno=atoi(ch_id);
cout<<"Enter GPA:";
gets(ch_gp);
emp.Gpa=atof(ch_gp);
}
私はそれを解決しようとしたが、私はmistake.Helpを把握できませんでした!
atoi()とatof()の両方が引数としてcharポインタを使用しますが、代わりにintとfloatの配列を渡しています。私はあなたが 'char ch_id [25];としてch_idを宣言したいと思うch_gpを 'char ch_gp [25];とします。代わりに。 –
@JeremyFriesnerしたがって、ch_idとch_gpのデータ型をcharに変更する必要がありますか? –
[C++で文字列をintに解析する方法は?](http://stackoverflow.com/questions/194465/how-to-parse-a-string-to-an-int-in-c) – VolAnd