Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

File pumper written in C-free for all *Along with Source*-Direct link

If you wanna contribute to the C++ forum you should post the source 😅
What compiler does is used for this program?
Hey, can I take a look at the source code?
Hmm... This is indeed very interesting idea.
Wonder how did you do it. (share your code :D)

My first guess was to open the file in ios::app | ios::binary, allocate shit loads of memory into char* and then write it into file:
Code
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
    size_t size;
    string filename;
    cin >> filename >> size;
    ofstream file(filename, ios::app | ios::binary);
    char* p = (char*)malloc(size*sizeof(char));
    file << p;
    free(p);
}

Tho it doesn't seem like a good idea, because it limited by RAM.

Second guess would be to allocate 1MB of ram and write 1 by one megabyte:
Code
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
    size_t size;
    string filename;
    cout << "Enter file name: ";
    cin >> filename;
    cout << "Enter size in MB: ";
    cin >> size;
    ofstream file(filename, ios::app | ios::binary);
    char* p = (char*)malloc(1048576*sizeof(char)); //Get 1 megabyte

    while(size != 0)
    {
  file << p;
  --size;
    }
    free(p);
}
Much more RAM friendly.

Can anyone think of better idea? :D


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by Farhan879Sep 5, 2020 07:58 PM 27 1,163 Sep 5, 2020 07:58 PM
Last Post: Astate
[C] by chill3d_boiJan 8, 2020 02:52 AM 10 816 Jan 8, 2020 02:52 AM
Last Post: strikemike
[Python] by arun hackerJan 14, 2017 09:28 PM 1 204 Jan 14, 2017 09:28 PM
Last Post: Black‌jack