Go Back   RunUO - Ultima Online Emulation > Developer's Corner > Programming > C/C++

C/C++ C/C++ Discussion

Reply
 
Thread Tools Display Modes
Old 02-03-2007, 11:59 AM   #1 (permalink)
Newbie
 
Join Date: Jan 2006
Posts: 34
Default First Run Only

Hey, I've got a problem. I'm trying to tell my program to check for the first runtime execution, and then branch off accordingly. I've got a deadline, so some fast help would be much appreciated.
Spunky_Man is offline   Reply With Quote
Old 02-03-2007, 12:56 PM   #2 (permalink)
Forum Expert
 
mordero's Avatar
 
Join Date: Nov 2003
Location: Illinois, USA
Age: 21
Posts: 2,911
Default

eeek first of all, those tags dont fit at all, maybe just make them one tag "first runtime" or "first execution"... anyways

Depending on the user's permissions you could either a) write to the registry and check if a key has been written or not or b)write a small file in the same directory as the application.
mordero is offline   Reply With Quote
Old 02-03-2007, 02:19 PM   #3 (permalink)
Newbie
 
Join Date: Jan 2006
Posts: 34
Default

Quote:
Originally Posted by mordero View Post
b)write a small file in the same directory as the application.
That's what I've been trying to do... Here's what I've been trying to do (keep in mind that these are cuts from the program, not the entire program):

Code:
// Cut 1: Prototypes...
int Config (int check, int firstrun);
int Config2 (string line, int firstrun);

// Cut 2: main()...
int main()
{
    int check;
    int firstrun;
    
    Config(check,firstrun);
    
    if (check == 1 && firstrun == 1)
    {
              ofstream config;
              config.open ("firstruncheck.sece", ios::out);
              config << "false";
              config.close();
              
              ofstream autoexec;
              autoexec.open ("autoexec.cfg", ios::out | ios::app);
              autoexec << "// SECE execution commands...\n";
              autoexec.close();
    }
    else
    {
        cout << "The program seems to have returned an error...\n";
    }
// Cut 3: Functions...
int Config (int check, int firstrun)
{
     string line;
     ifstream config ("firstruncheck.sece");
     if (config.is_open())
     {
                          while (!config.eof())
                          {
                                getline (config,line);
                                Config2(line,firstrun);
                                continue;
                          }
                          check = 1;
                          return (check,firstrun);
     }
     else
     {
         cout << "The program has returned an error...\n";
         cout << "Please try again...\n";
         main();
     }
}
// Function 2...
int Config2 (string line, int firstrun)
{
    if (line == "true")
    {
             firstrun = 1;
    }
    return (firstrun);
}
There ya have it. That is all of the relevant information. Can you correct it?
Spunky_Man is offline   Reply With Quote
Old 02-05-2007, 02:37 PM   #4 (permalink)
Forum Expert
 
milt's Avatar
 
Join Date: Nov 2003
Location: Hershey, PA
Age: 19
Posts: 1,601
Send a message via AIM to milt Send a message via Yahoo to milt Send a message via Skype™ to milt
Default

What is the output of the program?
__________________
--Milt, AKA Pokey
milt is offline   Reply With Quote
Old 02-06-2007, 03:55 AM   #5 (permalink)
Ray
Forum Novice
 
Join Date: Jul 2004
Location: Switzerland
Age: 25
Posts: 234
Default

This cannot succeed...

Code:
// Cut 1: Prototypes...
int Config (int check, int firstrun); Param passed as VALUE. References are denotated with &
int Config2 (string line, int firstrun);

// Cut 2: main()...
int main()
{
    int check;
    int firstrun;
    
    Config(check,firstrun); params passed as if they were references.
    //(check and firstrun now still uninitialized, containing random data)
    
    if (check == 1 && firstrun == 1)//both variables contain random data, The result of this check is random as well
    {
              ofstream config;
              config.open ("firstruncheck.sece", ios::out);
              config << "false";
              config.close();
              
              ofstream autoexec;
              autoexec.open ("autoexec.cfg", ios::out | ios::app);
              autoexec << "// SECE execution commands...\n";
              autoexec.close();
              // needs a return code. 'return 0'
    }
    else
    {
        cout << "The program seems to have returned an error...\n";
        // needs a return code. 'return 1'
    }
// Main lacks an ending } here. Keeps code seperated as obviously intended, without subfunctions.
// Cut 3: Functions...
int Config (int check, int firstrun)
{
     string line;
     ifstream config ("firstruncheck.sece");
     if (config.is_open())
     {
                          while (!config.eof())
                          {
                                getline (config,line);
                                Config2(line,firstrun);// calling this has no effect. firstrun is passed as value, not as reference. try a statement like 'firstrun = Config2(line);' after modifying the code
                                continue;//not needed at the end of a loop
                          }
                          check = 1; // check is a local parameter, not a reference. initialize will affect nothing here.
                          return (check,firstrun);// not valid. return code must be an int type. like 0
     }
     else
     {
         cout << "The program has returned an error...\n";
         cout << "Please try again...\n";
         main();//restarts main(), evokes an endless loop of calls. Should be 'return 1'
     }
}
// Function 2...
int Config2 (string line, int firstrun)
{
    if (line == "true")
    {
             firstrun = 1;
    }
    return (firstrun);
}
[/quote]

I didnt check the functions for validity, there can be more errors.
Good Luck
Ray is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5