473,799 Members | 2,746 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

limited no'of times execution

kk
Hi all,
How to write a c/c++ program to execute limited number of times.
if anybody know plz give reply.
thanks

Nov 15 '05 #1
7 1791
KK,

Probably you could have the number of times a program executed in a
persistent storage. Then each time you start the execution, compare
that with the maximum times you would want the program to execute. If
less, then increment the value -> write back to the storage,
automically and proceed normally. Else, abort.

Hope that helps.

Regards,
Sriram.

Nov 15 '05 #2
On 26 Jul 2005 02:05:59 -0700, "kk" <ki**********@g mail.com> wrote:
Hi all,
How to write a c/c++ program to execute limited number of times.
if anybody know plz give reply.
thanks


If you mean to loop a specific chunk of code within the program X
number of times, you can use a FOR loop or a WHILE loop

FOR loop:
=============== ====

int n; // my counter variable.
..
..
..
// Executes the code inside the loop 4 times.

for (n=0; n < 4; n++)
{
[your code goes here]
}
WHILE LOOP:
-loops so long as the condition in the brackets (n > 0) is true.
=============== =======
int n=4;

while (n > 0)
{
[your code goes here]
n--;
};

Do WHILE LOOP
-A variation of the While loop:
=============== =============== ====
int n=4;
do
{
[your code goes here]
n--;
}
while (n > 0);
With a DO-WHILE, the condition test isn't done until it's gone through
the code, so no matter what happens, the stuff inside the DO-WHILE
loop will run at least once. Even if the condition is totally false
to begin with. With the WHILE loop, if the condition is false, the
test happens at the beginning and if the condition is false, it will
skip over the code in the loop and it will never be run.
Try it yourself by setting n=0 using the examples shown above.
---------------------------------------------------------------------------

If you mean to limit the number of times that the user may run your
program, that's more of a program design thing than a language thing.
I'd imagine you'd have to use file IO or some feature of the OS to
store a counter value. Load up the old value each time it's run, and
increment the file value at some point during the program's run (at
start, after the initial check, or just before exit). It'd be pretty
easy to defeat, unless you disguised the way it was stored in some
way. All of this stuff is somewhat off topic and a bit more than I'd
like to think about at this early hour though.
---------------------------------------------

MCheu
Nov 15 '05 #3
SSM
Hello,

You can put command line argument and inside your program, you can repeat
the functionality required by a loop which has number of iterations=comm and
line argument.

Regards,
-SSM

"kk" <ki**********@g mail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
Hi all,
How to write a c/c++ program to execute limited number of times.
if anybody know plz give reply.
thanks

Nov 15 '05 #4
kk
Hello,

what my mean is, i execute the program from command line. Assume it you
can execute your program only 10 no'of times. Execution at 11th time it
should not allow to execute program.
it may possible throught volatile int but not sure. if anybody have an
idea or have a program, plz send it.
thanks in advance.

Regards,
kk

Nov 15 '05 #5
SSM
Hello KK,

Then what I can think of is:

Create one file if it is not existing, store integer count zero in it.

Next time whn you run, since the file already exist, you have to read count
(2nd time it will read zero),
compare against MAX_COUNT if less then increment and store in the file
again.

At some point the counter will reach maximum value and then program should
not execute.

Regards,
SSM
"kk" <ki**********@g mail.com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
Hello,

what my mean is, i execute the program from command line. Assume it you
can execute your program only 10 no'of times. Execution at 11th time it
should not allow to execute program.
it may possible throught volatile int but not sure. if anybody have an
idea or have a program, plz send it.
thanks in advance.

Regards,
kk

Nov 15 '05 #6
In article <11************ **********@f14g 2000cwb.googleg roups.com>,
kk <ki**********@g mail.com> wrote:


Hi all,
How to write a c/c++ program to execute limited number of times.
if anybody know plz give reply.
thanks


chellapas is that u?

Anyway, one amusing way to implement limited execution is
to open the running program itself and decrement a "constant"
in the program. At run time, check that the constant hasn't
been decremented too much. Some OS's don't let you do this
sort of thing, but many do.

In fact, I suspect there is nothing in the standard that
would prevent one from making a strictly conforming
program behave in a non-conforming manner by deleting or
overwriting itself!
--
7842++
Nov 15 '05 #7
"kk" <ki**********@g mail.com> writes:
what my mean is, i execute the program from command line. Assume it you
can execute your program only 10 no'of times. Execution at 11th time it
should not allow to execute program.
it may possible throught volatile int but not sure. if anybody have an
idea or have a program, plz send it.
thanks in advance.


A volatile int is unlikely to be helpful here.

Why do you want to do this?

The most obvious way is to use a file to record how many times the
program has executed. That's probably good enough if you're not
worried about the user manually modifying or removing the file.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
1644
by: Mr. x | last post by:
Hello, I need a script for counting the no. of enters on my site, please. I need a check that for the same user in the same day - if the user enter several times, it is count once (or something like this - I need that the script will accurate as possible). On the server side I have the .NET server. Thanks :)
3
2146
by: nrhayyal | last post by:
Hi All, thanks for reading this post. just wanted to know about the ratio of threads and processors. i am working on c++ on AIX5.2 platform. my c++ program are multithreaded programs. In a multithreaded application,should no of processors be equal to no of threads ? if we set the thread_scope to system( meaning 1 kernel thread to 1
1
1047
by: Mr. x | last post by:
Hello, I need a script for counting the no. of enters on my site, please. I need a check that for the same user in the same day - if the user enter several times, it is count once (or something like this - I need that the script will accurate as possible). On the server side I have the .NET server. Thanks :)
3
1025
by: redmond | last post by:
I am trying ot get a certain no of records from a DataView. I am looking ot do like a Top 15 in Sql, Is there a easy way to do this or should I loop till the count? Appreciate any help. -- Live one day at a time.
0
1357
by: nitinsharma717 | last post by:
hi, Front End : Win Forms (Visual Studio 2005) Back End : Ms Sql Server 2005 In the code i have to Show No.of database deadlocks and No. of transactions per second/minute of the Database server.There are other informations for which i am using SMO Objects.I have checked all the properties of SMO Objects but i am not getting these properties.
0
827
by: ajaspersonal | last post by:
plz.. ny one help me.. i wana 2 count the no of selected item from a list box(only selected item's no) how it's possible (asp.net with vb codin)
6
3649
sumittyagi
by: sumittyagi | last post by:
Hi! to all! I have got an issue. * I maintain serial no. of rows tables in a column serial_no(which is set as primary key). * while inserting i count the no of rows, "select count(*) from tbl", and increment one to it, and assign that as serial no to new row to be inserted. is it the right way to achieve this. or is there any other better way to do it. thanks in advance for your help.
0
1185
by: Fareast Adam | last post by:
Hi all, anybody know how to create dynamic array random password (lenght and no of password)? The program request an user to insert no of password AND lenght of password to be generate. After that, update the current new password into db with selected user only... Ur help will be appreciate! Thanks... Regard, Fareast Adam
75
3559
by: ume$h | last post by:
/* I wrote the following program to calculate no. of 'a' in the file c:/1.txt but it fails to give appropriate result. What is wrong with it? */ #include"stdio.h" int main(void) { FILE *f; char ch; long int a=0;
0
9543
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10488
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10237
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7567
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5588
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.