So I tried making a function in C++ that converts each character entered by a user into a ‘*’. But when I run the .exe file (CMD) it asks for the password alright, however when I enter a word it gives me an error: “Debug assertion failed.” Any idea why this happens?
Here’s my code:
#include "stdafx.h"
#include "iostream"
#include "conio.h"
#include "string"
#include "ctype.h"
using namespace std;
void encrypt(char string[], int len)
{
for (int count = 0; count < len; count++)
if (isalpha (string [count] ) )
string[count] = '*';
}
int _tmain(int argc, _TCHAR* argv[])
{
char Text[40];
int Size = strlen(Text);
cout << "Enter your desired password: ";
cin >> Text;
encrypt(Text, Size);
cout << Text << endl;
_getch();
return 0;
}
Just move “int Size = strlen(Text) after the line “cin >> Text;”