1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Made a little Craigslist Ad Body Mixer

Discussion in 'C, C++, C#' started by _Austin, Apr 11, 2009.

  1. _Austin

    _Austin Junior Member

    Joined:
    Apr 9, 2009
    Messages:
    147
    Likes Received:
    39
    It isn't a straight up full program as much as just a utility that people with a C++ compiler can use. I do have plans to make this a bit more user friendly and more powerful in the coming weeks.


    main.cpp
    PHP:
    #include <iostream>
    // for file writing
    #include <fstream>
    // for seeding the rand
    #include <ctime>
    using namespace std;

    int mainvoid )
    {

        
    // seed the rand function
        
    srandunsigned inttime) ) );

        
    // set up a char pointer array for each section of your ad that you would like dynamic
        // then determine the appropriate size of the array and add the different selections
        
    chargreeting[6] = { "Hey,""Hello,""What's up,""Hey there,""How's it goin?""Hi," };
        
    charreason[5]   = { "example1""example2""example3""example4""example5" };
        
    charwhy[5]      = { """""""""" };
        
    chardecide[4]   = { """""""" };
        
    charclose[4]    = { """""""" };

        
        
    // this will make your file for you - anything you name it in the " "
        
    ofstream myfile("clposts.txt");
          

        
    // amount of random ad copies: if 20 then ( 0 -> 19 )
        
    for( int a 020; ++)
        {
                            
            if (
    myfile.is_open())
            {
                
                
    /*
                This formats as:

                Ad Copy #:
                Title:
                Body:

                
                ---------------------------------------------------------
                */
                
    myfile << "Ad Copy " << ( ) << ':' << endl;
                
    myfile << "Title: " << endl << "Body: ";
                
    myfile << greetingrand()%] << " I'm " << reasonrand()%] << " soon and since "
                
    << whyrand()%] << " I've " << deciderand()%] << " to " << closerand()%] << '.'
                
    << endl << endl << endl;
                
    myfile << "---------------------------------------------------------" << endl;
                
            }
            else 
                
    // if it can't make the file for some reason
                
    cout << "Unable to open file";

        }


        
    // close the file connection
        
    myfile.close();


        
    system"pause" );
        return 
    0;


    *php tags for the syntax highlighting*


    _Austin

     
    Last edited: Apr 11, 2009
  2. gregowen

    gregowen Newbie

    Joined:
    Apr 11, 2009
    Messages:
    1
    Likes Received:
    0
    I tried to compile it and got an error on this line
    Code:
    srand( unsigned int( time( 0 ) ) );
    The error was:
    13 C:\Dev-Cpp\main.cpp expected primary-expression before "unsigned"

    I removed that line and it compiled with no further issues. When I run it, it prompts me to press any key to continue, then closes.

    I'm guessing its totally my fault, I know almost nothing about C or C++. But I do know php and the syntax is close enough I thought I might be able to compile it.

    Thanks anyway, for your contribution. And any help would be appreciated!
     
  3. cgFuse

    cgFuse Newbie

    Joined:
    Apr 18, 2009
    Messages:
    39
    Likes Received:
    2
    Yea, i got the same error.
     
  4. _Austin

    _Austin Junior Member

    Joined:
    Apr 9, 2009
    Messages:
    147
    Likes Received:
    39
    What compiler are you running this in and what OS are you on?
     
  5. Valliko

    Valliko Newbie

    Joined:
    Apr 28, 2009
    Messages:
    4
    Likes Received:
    2
    Try changing it to srand(time(NULL));
    Sometimes declaring variables inside functions will go *boom* i suppose.