Baran Topal

Baran Topal


April 2024
M T W T F S S
« Feb    
1234567
891011121314
15161718192021
22232425262728
2930  

Categories


Generating huge text file for mocking.

baranbaran

 

 

Today, I am going to explain creating a huge text file via C.

Clearly, this is easier with OOP languages such as Java and C#.NET.

Yet, for fun, I am sharing here a straight forward approach for creating a huge file.

I don’t think I should write any comment on this, since my codes are always very well commented. 🙂

This is also shared in dropbox, in the link: https://dl.dropbox.com/u/1327371/HugeFileMocking.rar

/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Company: - *
* Deadline: - *
* To: - *
* Programmer: Baran Topal *
* Solution: HugeFileMocking *
* Project name: HugeFileMocking *
* Folder name: SourceFiles *
* File name: HugeFile.cpp *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* LICENSE: This source file is subject to have the protection of GNU General Public License. *
* You can distribute the code freely but storing this license information. *
* Contact Baran Topal if you have any questions. barantopal@barantopal.com *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/

// preprocessor directives
# include 
# include 
// file size set by you
# define FILESIZE 500000000

// main gate
void main()
{
	// buffer length
	int bufflen = 50 * 1024;

	// temp param to keep bufflen to be positive
	int actual;
	int strsize;

	// creating buffer
	char * buffer = new char[bufflen];

	// variable to keep the randomized string
	char randstr[9];

	// filling buffer with default char values
	*buffer = '\0';

	// i am lazy, I actually didn't create a randomized string
	// but put a fixed string to randstr variable, you can randomize a string
	strcpy(randstr, "abcd1234");
	strsize = strlen(randstr);

	while (bufflen >= 0)
	{
		// populate buffer
		strcat(buffer, randstr);
		// preserve buffer in another variable
		actual = bufflen;
		bufflen -= strsize;
		// keep buffer positive
		if(bufflen

Comments 0
There are currently no comments.