C ++ Ввод мусора в текстовые файлы - PullRequest
0 голосов
/ 21 сентября 2019

Программа компилируется и запускается, но когда я открываю файл - все предложения написаны правильно, но первые 3 предложения содержат ненужные символы

Часть с ошибкой закомментирована.

/*file5.open(location,ios::app);
file5.write(first_name,100);file5<<endl;
file5.write(last_name,100);file5<<endl;
file5.write(country,100);file5<<endl;
file5.write(mobile_number,100);file5<<endl;
file5.write(email,100);file5<<endl;
file5.write(address[0],100);file5<<endl;
file5.write(address[1],100);file5<<endl;
file5.write(address[2],100);file5<<endl;*/

Ниже приводится выходной файл

enter image description here

и полные коды.

void new_customer()

clrscr();
textcolor(CYAN);
char first_name[100],last_name[100],country[100],mobile_number[100],mob_code[100];
char email[100],address[3][100],password[100],di[100],di2[100];
char location[100]="C:\\TURBOC3\\BIN\\CSHOP\\",location1[100];
strcpy(location1,location);
ofstream file,file1,file2,file3,file4,file5;
int check=1,i;
char final_mob[100];
file.open("C:\\TURBOC3\\BIN\\CSHOP\\uemail.txt",ios::app);
file1.open("C:\\TURBOC3\\BIN\\CSHOP\\uphone.txt",ios::app);
file2.open("C:\\TURBOC3\\BIN\\CSHOP\\upass.txt",ios::app);
file3.open("C:\\TURBOC3\\BIN\\CSHOP\\uids.txt",ios::app);
cprintf("Welcome To The E - Shop");cout<<endl;
cprintf("Enter Your First Name : ");
gets(first_name);
cprintf("Enter Your Last Name : ");
gets(last_name);
cprintf("Enter Country : ");
gets(country);
mobile_code_finder(country,mob_code,check);
char ch;
long long balance = 6000;
char denoted[100],id[100];
cprintf("Enter Mobile Number : ");
cout<<mob_code;
for(i=0;i<11;i++)
{
    if(i!=5)
    {
        ch=getch();
        mobile_number[i]=ch;
        cout<<ch;
    }
    else
    {
        cout<<" ";
        mobile_number[i]=' ';
    }
}
cout<<endl;
strcat(mob_code,mobile_number);
strcpy(final_mob,mob_code);
strcpy(mobile_number,final_mob);
file1.write(mobile_number,100);
file1<<endl;
cprintf("Enter Your Email : ");
gets(email);
file.write(email,100);
file<<endl;
cprintf("Enter Address Below : ");cout<<endl;
for(i=0;i<3;i++)
{
    textcolor(YELLOW);
    cprintf("#Enter Address Line %d : ",i+1);
    gets(address[i]);
}
currency(country,balance,denoted);
textcolor(WHITE);
cprintf("Enter Your Password : ");
gets(password);
password_cryptor(password);
file2.write(password,100);
file2<<endl;
cprintf("Your Current Balance Is : ");
textcolor(GREEN);
cprintf("%d",balance);cout<<denoted;
id_generator(country,id,email);
textcolor(YELLOW);
cout<<endl;
cprintf("Your ID Is : %s ",id);
cout<<endl;
strcpy(di,id);
strcpy(di2,di);
strcat(di,".txt");
strcat(di2,"C.txt");
strcat(location,di);
strcat(location1,di2);
file4.open(location1,ios::app);
file4<<"Cart"<<endl;
/*file5.open(location,ios::app);
file5.write(first_name,100);file5<<endl;
file5.write(last_name,100);file5<<endl;
file5.write(country,100);file5<<endl;
file5.write(mobile_number,100);file5<<endl;
file5.write(email,100);file5<<endl;
file5.write(address[0],100);file5<<endl;
file5.write(address[1],100);file5<<endl;
file5.write(address[2],100);file5<<endl;*/
file3.write(id,100);
file3<<endl;
textcolor(GREEN);
cprintf("Your Account Has Been Created Successfully");
if(!check)
{
    file.clear();
    file1.clear();
    file2.clear();
    file3.clear();
    file4.clear();
    file5.clear();
}

file.close();
file1.close();
file2.close();
file3.close();
file4.close();
file5.close();
...