Program crashed at the start of third loop.
Feb 19, 2018 at 1:27am UTC
Hello every one, I am newbie in C++ Programming, my program always crash at the start of the third loop. Hope every one can help me fix it, here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#include <iostream>
#include <iomanip>
#include <bitset>
#include <random>
using namespace std;
/* Hàm chuyển chuỗi sang mã nhị phân */
string nhiphan( string chuoi )
{
string chuoixuatra;
for (size_t i = 0; i < chuoi.size(); ++i)
{
bitset<8> b = chuoi.c_str()[i];
chuoixuatra += b.to_string();
}
return chuoixuatra;
}
/* Hàm sinh mã khóa ngẫu nhiên */
string khoangaunhien(string dodai)
{
string ngaunhien;
for (int i = 0; i < dodai.length(); i++)
{
int songaunhien = rand()%2;
ngaunhien += to_string(songaunhien);
}
return ngaunhien;
}
/* Hàm mã hóa */
string mahoa( string chuoicanmahoa)
{
cout << "Chuyen chuoi tu dang ASCII sang nhi phan:..." << endl;
string chuoinhinphan = nhiphan(chuoicanmahoa);
cout << chuoinhinphan << endl;
cout << "Sinh khoa ma ngau nhien:..." << endl;
string khoann = khoangaunhien(chuoinhinphan);
cout << khoann << endl;
cout << "Chuoi duoc ma hoa o dang Nhi phan la: " << endl;
for (int i = 0; i<chuoinhinphan.size(); i++)
{
cout << (chuoinhinphan[i] ^ khoann[i]);
}
}
int main()
{
string khoa;
cout << endl;
cout << "Nhap chuoi can ma hoa: " << endl;
getline(cin, khoa);
mahoa(khoa);
cin.ignore();
return main();
}
Feb 19, 2018 at 3:09am UTC
You have multiple loops, which one ?
Feb 19, 2018 at 3:26am UTC
the mahoa() function in main() always crash at third loop
Topic archived. No new replies allowed.