Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- #include <ctype.h>
- #include <cstdio>
- using namespace std;
- string mocking_spongebob_generator(const string& text) {
- string result = "";
- for (unsigned i = 0; i < text.size(); ++i) {
- bool character_flag = rand() % 2;
- if (character_flag) {
- result += tolower(text[i]);
- } else {
- result += toupper(text[i]);
- }
- }
- return result;
- }
- bool save_to_file(const string& text) {
- FILE *f = fopen("spongebob_generated.txt", "w");
- if (!f) return false;
- for (unsigned int i = 0; i < text.size(); ++i) {
- fprintf(f, "%c", text[i]);
- }
- fclose(f);
- return true;
- }
- int main(int argc, char **argv) {
- if (argc <= 1) {
- cerr << "no args";
- return 1;
- }
- srand(time(NULL));
- string text;
- for (int i = 1; i < argc; ++i) {
- text += argv[i];
- text += " ";
- }
- text = mocking_spongebob_generator(text);
- save_to_file(text);
- return 0;
- }
Add Comment
Please, Sign In to add comment