2017-02-20 9 views
1

これは不完全なプログラムの小さな部分です。プログラムは入力ファイルを読み込み、計算して出力ファイルに出力しますが、出力ファイルには奇妙なシンボルがあります。プログラムが出力ファイルに奇妙なシンボルを出力するC++

void printRecord (char name[20], char Id[20], ostream& outfile) 
{ 
outfile << name << Id << endl; 
} 

int main() 
{ 
ofstream outfile; 
ifstream infile; 


char file_nameI[21], file_nameO[21], name[20], Id[8]; 

float hworkgrade, grade1; 
int deductions; 

cout << "Please enter name of input file: "; 
cin >> file_nameI; 
infile.open(file_nameI); 
if (!infile) 
{ 
    cout << "Could not open input file \n"; 
    return 0; 
} 

cout << "Please enter name of output file: "; 
cin >> file_nameO; 
outfile.open(file_nameO); 
if (!outfile) 
{ 
    cout << "Could not open output file \n"; 
    return 0; 
} 

do 
{ 
    infile >> name >> Id; 
    cout<< name << Id; 
    hworkgrade = CalHworkGrade(grade1, infile); 
    printRecord(name, Id, outfile); 
} 
while(!infile.eof()); 

return 0; 
} 

これは、出力ファイル

Фにあったもので、ью\XаѓФ、ью

+2

これは通常、初期化されていない変数を印刷することによって発生します。 – drescherjm

+0

あなたは正しいです。今は、プログラムが入力ファイルから新しい情報を引き出していない理由を理解しなければなりません。助けてくれてありがとう! – Morgan

答えて

0

プログラムは、入力ファイルから情報を引っ張っていません。変数をhelloに設定すると、新しい情報で上書きされず、プログラムはhelloを出力します

char file_nameI[21], file_nameO[21], name[20] = hello , Id[8] = hello;