Click here to Skip to main content
15,914,447 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to CREATE file with CFile? Pin
User 842017-Jul-02 10:38
User 842017-Jul-02 10:38 
GeneralRe: How to CREATE file with CFile? Pin
Raphael Kindt17-Jul-02 10:47
Raphael Kindt17-Jul-02 10:47 
Generalusing inherited MFC dialog classes Pin
moredip17-Jul-02 10:23
moredip17-Jul-02 10:23 
GeneralRe: using inherited MFC dialog classes Pin
Joaquín M López Muñoz17-Jul-02 11:11
Joaquín M López Muñoz17-Jul-02 11:11 
GeneralRe: using inherited MFC dialog classes Pin
moredip17-Jul-02 11:39
moredip17-Jul-02 11:39 
GeneralRe: using inherited MFC dialog classes Pin
Joaquín M López Muñoz17-Jul-02 11:44
Joaquín M López Muñoz17-Jul-02 11:44 
GeneralOwnerDraw stuff working differently in Win2K. Pin
Chris Meech17-Jul-02 9:26
Chris Meech17-Jul-02 9:26 
Generalsludgy character array problem Pin
John Aldrich17-Jul-02 8:39
John Aldrich17-Jul-02 8:39 
I'm having problems with an array tacking a bunch of sludge on to the end of a array of random characters. It needs to generate an array of 64 random bytes for use inan encryption routine. I'm getting the 64 bytes of information that I want at the front end of the array, BUT..it's also tacking on the contents of the original array that I filled with a sequence from ASCII 32 to ASCII 127 character values. My question is how to get the sludge off the end of the array so it consists of just teh 64 random byte values. Source Code Follows:

// seed a random number generator with the current
// tick count.  we will use this as an iterator in
// the szRandomBytes array a bit later


srand(GetTickCount());


// set some values so that we only get legal characters
// from the szStringArray which will be used to fill
// the szRandomBytes array with legal characters


int nElementCount = 0;
int nElementValue = 32;


// set up our two arrays.  szStringArray gets filled 
// with legal character values.  szRandomBytes uses
// the values in szStringArray to generate a random
// character string that we can use for encryption


char szStringArray[95] = "";
char szRandomBytes[64] = "";


// filling the array

	
while ( nElementCount <= 94 )
{
	szStringArray[nElementCount] = nElementValue;
	nElementCount++;
	nElementValue++;
}


//  set iterator to zero


nElementCount = 0;


// pull 64 random characters out of the array
// to create our random string for encoding


while (nElementCount <=63)
{
	

	// get a random number


	int nRandomNumber = rand();

	
	// checking it out.  if its greater than 95
	// we divide it until its with the bounds of
	// the szStringArray.


	while (nRandomNumber >= 95)
	{
		nRandomNumber = nRandomNumber / 2;
	}


	// using nRandomNumber and szStringArray to assign
	// a value to the Element Number that szRandomBytes
	// is currently on up to a possible 64 characters


	szRandomBytes[nElementCount] = szStringArray[nRandomNumber];

	
	// incrementing the element count so
	// that the next value gets filled.

	
	nElementCount++;
}


// debug check


MessageBox(NULL, szRandomBytes, "Random String From Array", MB_OK);




It's good to see kids turning their minds to wholesum activities such as programming, instead of wasting their lives in the hedonistic disciplines of Sex, Drugs, & Rock & Roll... or Sex with Drugs, or Sex with Rocks while Rolling in Drugs, or whatever new-fangled perversions you little monsters have thought up now...

[Shog9 on Kid Programmers]
GeneralRe: sludgy character array problem Pin
Ranjan Banerji17-Jul-02 9:15
Ranjan Banerji17-Jul-02 9:15 
GeneralRe: sludgy character array problem Pin
jmkhael17-Jul-02 10:14
jmkhael17-Jul-02 10:14 
GeneralUnicode + console app + cout Pin
Chris Losinger17-Jul-02 8:25
professionalChris Losinger17-Jul-02 8:25 
GeneralRe: Unicode + console app + cout Pin
Navin17-Jul-02 10:33
Navin17-Jul-02 10:33 
GeneralRe: Unicode + console app + cout Pin
Chris Losinger17-Jul-02 10:49
professionalChris Losinger17-Jul-02 10:49 
GeneralRe: Unicode + console app + cout Pin
Daniel Lohmann17-Jul-02 13:58
Daniel Lohmann17-Jul-02 13:58 
QuestionTitle Bar Font? Pin
Dave_17-Jul-02 8:14
Dave_17-Jul-02 8:14 
AnswerRe: Title Bar Font? Pin
Anonymous17-Jul-02 8:27
Anonymous17-Jul-02 8:27 
GeneralRe: Title Bar Font? Pin
Dave_17-Jul-02 8:28
Dave_17-Jul-02 8:28 
AnswerRe: Title Bar Font? Pin
Jeremy Falcon17-Jul-02 11:29
professionalJeremy Falcon17-Jul-02 11:29 
QuestionTrayClock??? Pin
kekeguo17-Jul-02 8:12
kekeguo17-Jul-02 8:12 
GeneralQuestion about sequence of events Pin
ns17-Jul-02 8:12
ns17-Jul-02 8:12 
GeneralRe: Question about sequence of events Pin
Ravi Bhavnani17-Jul-02 9:07
professionalRavi Bhavnani17-Jul-02 9:07 
GeneralWoW! Most excellent! Pin
ns17-Jul-02 9:10
ns17-Jul-02 9:10 
GeneralRe: WoW! Most excellent! Pin
Ravi Bhavnani17-Jul-02 9:31
professionalRavi Bhavnani17-Jul-02 9:31 
Generalstring initialization problem Pin
ChiYung17-Jul-02 8:07
ChiYung17-Jul-02 8:07 
GeneralRe: string initialization problem Pin
Joaquín M López Muñoz17-Jul-02 8:16
Joaquín M López Muñoz17-Jul-02 8:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.