473,409 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

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 1773
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**********@gmail.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=command
line argument.

Regards,
-SSM

"kk" <ki**********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.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**********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.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**********************@f14g2000cwb.googlegroups .com>,
kk <ki**********@gmail.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**********@gmail.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_Keith) 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
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...
3
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...
1
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...
3
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. --...
0
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...
0
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
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...
0
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,...
75
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;...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.