executable file runs on some computers, not all

A

Andrew

Hello,
I have a small C program I wrote for calculating loan depreciation. I
have been using the program for years, without problems. A couple
months ago I sent the file to my sister and she could not get it to
run. She said that when she tried to run it, the DOS window would
come up for a second and then disappear. She has XP Home Ed. A
couple days ago, I emailed the file to myself at work. I had the same
problem. I have XP Pro at work. The DOS window pops up for a second
and disappears. I have sent this program to people many times and it
has always worked. The program works fine on my compter (I have XP
Pro). This has to be a setting on the computer which is disabling the
program from running. Has anyone encountered this problem? Does
anyone know how to fix it?

thanks,
Andy
 
T

Tomás Ó hÉilidhe

So you're saying it works on *some* Windows XP machines but not on
all. If it works on *any* Windows XP machines then that means the
executable is indeed "binary compatible" with Windows XP.

On the computer where it doesn't work, click the Start button and then
click Run. Type in "cmd" and hit Return. Use "cd" to navigate to the
directory that contains the executable, then type the name of the
executable and hit Return. There might be some text written to the
screen to indicate that an error has occurred.

If you have access to one of the machines on which it doesn't work,
you can use a debugger such as gdb to single-step through the program
until the point at which it fails.

Some things come to mind though:
1) The machines on which it doesn't work might be "newer" in that they
have service packs installed. These service packs might have security
features that kill a program when it does certain things.

If it's a small program, you can post the source code here and some of
us might be able to point out something that could be causing a
problem.
 
I

Ian Collins

Andrew said:
Hello,
I have a small C program I wrote for calculating loan depreciation. I
have been using the program for years, without problems. A couple
months ago I sent the file to my sister and she could not get it to
run.

Then rebuild it for her platform.

If you have an issue with the code, post it here. If you have a windows
issue, post it to a windows group.
 
T

Tomás Ó hÉilidhe

Who said what?

The author of the post just above mine in the thread hierarchy.
Threading was invented some time in the 20th Century I believe, and
has enjoyed a majority uptake within the internet discussion
community. Here's some info:

http://en.wikipedia.org/wiki/Threaded_discussion

Threading is advantageous to the reader in keeping track of a
discussion, i.e. who's responding to whom, and also it cuts down on
the need for excessive quoting (as I took advantage of in my most
recent post).

I wholeheartedly recommend that you give threading a try, it has
revolutionised internet discussion.
 
A

Andrew

So you're saying it works on *some* Windows XP machines but not on
all. If it works on *any* Windows XP machines then that means the
executable is indeed "binary compatible" with Windows XP.

On the computer where it doesn't work, click the Start button and then
click Run. Type in "cmd" and hit Return. Use "cd" to navigate to the
directory that contains the executable, then type the name of the
executable and hit Return. There might be some text written to the
screen to indicate that an error has occurred.

If you have access to one of the machines on which it doesn't work,
you can use a debugger such as gdb to single-step through the program
until the point at which it fails.

Some things come to mind though:
1) The machines on which it doesn't work might be "newer" in that they
have service packs installed. These service packs might have security
features that kill a program when it does certain things.

If it's a small program, you can post the source code here and some of
us might be able to point out something that could be causing a
problem.

Here's the code: I am by no means a highly-skilled C programmer, but
there just isn't much in this program to go wrong. Another thing
worth noting is that the program doesn't run at all on some machines.
I'm not saying it fails to run, because that would mean the code
stopped somewhere. In this case, it is like the computer doesn't
even know it's there.

/* --- The following code comes from C:\lcc\lib\wizard\textmode.tpl.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


double amount,down,payment,pay_m,taxes,tax_m,insurance,ins_m,

extra,borrowed,num,den,years,months,T,interest,int_m,principal_pay;
double balance[1000], total_int[1000],inputs[6];
char x,name[80],printname[]={"notepad.exe "};
int n,count=1,k,flag;
void prog_header(void);
void print_results(void);
void print_file(void);
FILE *fp;
double get_values(double arg[]);



int main(void)
{
system("CLS");
prog_header();
restart:


n=0;
k=0;
amount=0;
down=0;
interest=0;
taxes=0;
months=0;
extra=0;

printf("\n\nEnter name of output file (no spaces): ");
scanf(" %s",&name);
//fgets(name,20,stdin);
strcat(name,".txt");

printf("Enter full purchase price: $");
scanf(" %lf",&amount);
printf("Enter downpayment: $");
scanf(" %lf",&down);
printf("Enter annual interest rate (as percent not decimal): ");
scanf(" %lf",&interest);
printf("Enter annual taxes & insurance: $");
scanf(" %lf",&taxes);
printf("Enter life of loan (months): " );
scanf(" %lf",&months);
//printf("Enter extra payment per month: " );
//scanf(" %lf",&extra);


tax_m=taxes/12;
borrowed=amount-down;
int_m=interest/1200;
pay_m=(int_m*borrowed)/(1-pow((1+int_m),-months))+tax_m;
principal_pay=pay_m-tax_m;

T=0;
balance[0]=borrowed;
for(n=1;n<=months;n++)
{
balance[n]=(1+int_m)*balance[n-1]-pay_m+tax_m;
total_int[n]=balance[n-1]*int_m;
T=T+total_int[n];
}
print_results();
print_file();

printf("\n\n\n\n\n");
printf("What do you want to do?");
printf("\n\n[1] Enter another loan\n[2] View output file\n[3] Quit
Program\n\t");
scanf("%i",&flag);

if(flag==1)
{
system("CLS");
goto restart;
}
if(flag==2)
{
strcat(printname,name);
system("CLS");
printf("\nOpening %s\n\n",printname);
system(printname);
system("PAUSE");
}


}




void prog_header(void)
{

printf("\n\n * * * LOAN PAYMENT CALCULATOR * * * \n\n");
printf("\nThis program will do the following....");
printf("\n\n [1] This will determine how large your monthly loan
payments will be");
printf("\n [2] Total amount of interest paid during the life of the
loan.");
printf("\n [3] Create an amortization schedule for the life of the
loan.");
printf("\n [4] Enter 0 for taxes and insurance to see pure loan
results.");
}


void print_results(void)
{
printf("\n\n\n RESULTS \n");
printf(" --------------------------------------- ");
printf("\n\t Filename: %s",name);
printf("\n\t Amount of loan: $%0.2f",borrowed);
printf("\n\t Interest rate: %1.4f%%",interest);
printf("\n\t Monthly payment: $%.2f",pay_m);
printf("\n\t Annual Taxes/Ins: $%.2f",taxes);
printf("\n\t Total interest paid: $%.2f",T);
printf("\n\t Total to be paid back: $%.2f",T+amount);
}





void print_file(void)
{
double cum_int,cum_pay,cum_pri,cum_tax;
fp=fopen(name,"w");
fprintf(fp,"\n********************************************");
fprintf(fp,"\n Loan Amortization Schedule");
fprintf(fp,"\n********************************************\n\n");
fprintf(fp, "Filename: %s\n",name);
fprintf(fp, "Purchase Amount: $%.2f\n",amount);
fprintf(fp, "Down payment: $%.2f\n",down);
fprintf(fp, "Loan Amount: $%.2f\n",borrowed);
fprintf(fp, "Loan Duration: %.0f months\n",months);
fprintf(fp, "Interest rate: %1.4f%%\n",interest);
fprintf(fp, "Annual Taxes/Ins.: $%1.2f\n",taxes);
fprintf(fp, "Monthly payment: $%.2f\n",pay_m);
fprintf(fp, "Total interest paid: $%.2f\n\n\n",T);
fprintf(fp, "Payment Payment Interest Tax/Ins
Principal Remaining Cumulative Cumulative
Cumulative\n");
fprintf(fp, "Number Amount Paid Paid
Paid Balance Interest Principal Tax and
Ins.\n");
fprintf
(fp,"---------------------------------------------------------------------------------------------------------------------
\n");
cum_int=0;
cum_pay=0;
cum_pri=0;

for(n=1;n<=months;n++)
{
cum_int=cum_int+total_int[n];
cum_pay=cum_pay+pay_m; // sum of all payments
cum_tax=tax_m*n;
cum_pri=pay_m*n-tax_m*n-cum_int;

fprintf(fp,"%3d %11.2f %11.2f %11.2f %13.2f %14.2f %14.2f %14.2f
%14.2f\n", n,pay_m,total_int[n],tax_m,pay_m-total_int[n]-tax_m,balance
[n],cum_int,cum_pri,cum_tax);

}
fclose(fp);

}
 
B

Ben Bacarisse

Andrew said:
Here's the code: I am by no means a highly-skilled C programmer, but
there just isn't much in this program to go wrong. Another thing
worth noting is that the program doesn't run at all on some machines.
I'm not saying it fails to run, because that would mean the code
stopped somewhere. In this case, it is like the computer doesn't
even know it's there.

The program has several system specific parts but also some errors.
Technically, your program exhibits what is called undefined behaviour
(the C standard declines to say anything about what your program
means) and it would be wise to remove these first.

As already suggested: run the program from a command window to be sure
what it is really doing.
/* --- The following code comes from C:\lcc\lib\wizard\textmode.tpl.
*/

OK, you did not ask for comments but I can't help it...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


double amount,down,payment,pay_m,taxes,tax_m,insurance,ins_m,

extra,borrowed,num,den,years,months,T,interest,int_m,principal_pay;
double balance[1000], total_int[1000],inputs[6];
char x,name[80],printname[]={"notepad.exe "};

The last part declares an array of 13 chars. You can't add any more
without getting the dreaded "undefined behaviour".
int n,count=1,k,flag;
void prog_header(void);
void print_results(void);
void print_file(void);
FILE *fp;
double get_values(double arg[]);



int main(void)
{
system("CLS");
prog_header();
restart:

I don't like gotos. I also don't like variables called 'flag'.
Similarly, I'd name the actions in an enum (or with #defines). The
upshot is that I would re-write the top level as a do .. while loop
with this shape:

do {
/* one round of processing */

printf("\n\n[%d] Enter another loan\n"
"[%d] View output file\n"
"[%d] Quit Program\n\t", GO_AGAIN, VIEW_OUTPUT, QUIT);

} while (scanf("%i", &action) == 1 && action == GO_AGAIN);

if (action == VIEW_OUTPUT) {
/* your viewing code... *.
}
n=0;
k=0;
amount=0;
down=0;
interest=0;
taxes=0;
months=0;
extra=0;

printf("\n\nEnter name of output file (no spaces): ");
scanf(" %s",&name);
//fgets(name,20,stdin);
strcat(name,".txt");

printf("Enter full purchase price: $");
scanf(" %lf",&amount);
printf("Enter downpayment: $");
scanf(" %lf",&down);
printf("Enter annual interest rate (as percent not decimal): ");
scanf(" %lf",&interest);
printf("Enter annual taxes & insurance: $");
scanf(" %lf",&taxes);
printf("Enter life of loan (months): " );
scanf(" %lf",&months);
//printf("Enter extra payment per month: " );
//scanf(" %lf",&extra);

You should really test the result from scanf (BTW, you don't need the
space in front of the %lf). Because you do this a lot, I'd write a
function to prompt the user for an input and keep going until a
suitable input is seen. A first go might look like this:

double ask_for(const char *prompt)
{
double number;
while (!ferror(stdin) && !feof(stdin)) {
int c;
printf("%s: ", prompt);
fflush(stdout);
if (scanf("%lf", &number) == 1)
return number;
while ((c = getchar()) != EOF && c != '\n');
}
return 0;
}
tax_m=taxes/12;
borrowed=amount-down;
int_m=interest/1200;
pay_m=(int_m*borrowed)/(1-pow((1+int_m),-months))+tax_m;
principal_pay=pay_m-tax_m;

T=0;
balance[0]=borrowed;
for(n=1;n<=months;n++)
{
balance[n]=(1+int_m)*balance[n-1]-pay_m+tax_m;
total_int[n]=balance[n-1]*int_m;
T=T+total_int[n];
}
print_results();
print_file();

printf("\n\n\n\n\n");
printf("What do you want to do?");
printf("\n\n[1] Enter another loan\n[2] View output file\n[3] Quit
Program\n\t");
scanf("%i",&flag);

if(flag==1)
{
system("CLS");
goto restart;
}
if(flag==2)
{
strcat(printname,name);

This is the killer. There is no spare room in which to "cat" any
further characters.
system("CLS");
printf("\nOpening %s\n\n",printname);
system(printname);
system("PAUSE");
}


}
<snip>
 
V

viza

Hi

The DOS window pops up for a second and disappears. I have sent this
program to people many times and it has always worked.

This has nothing to do with C.

....but try this:

Right click and drag the file somewhere and select create shortcut.
right click on the short cut and select properties. Change the options
so that window isn't automatically closed.

HTH
viza
 
C

CBFalconer

Andrew said:
I have a small C program I wrote for calculating loan depreciation.
I have been using the program for years, without problems. A couple
months ago I sent the file to my sister and she could not get it to
run. She said that when she tried to run it, the DOS window would
come up for a second and then disappear. She has XP Home Ed. A
couple days ago, I emailed the file to myself at work. I had the
same problem. I have XP Pro at work. The DOS window pops up for a
second and disappears. I have sent this program to people many
times and it has always worked. The program works fine on my
compter (I have XP Pro). This has to be a setting on the computer
which is disabling the program from running. Has anyone encountered
this problem? Does anyone know how to fix it?

Bring up a CLI window, basically by running CMD.EXE at startup.
Run your program from that. Microsoft tries hard to make running
non-GUI things impossible.
 
C

CBFalconer

Tomás Ó hÉilidhe said:
The author of the post just above mine in the thread hierarchy.
Threading was invented some time in the 20th Century I believe, and
has enjoyed a majority uptake within the internet discussion
community. Here's some info:

Usenet is a best-efforts delivery mechanism. There is never any
reason to assume that any other reader has read, can read, or will
ever read such previous messages. That is why any decent
newsreader includes facilities for quoting, snipping attribution,
etc. Ignoring this elementary practice helps get you plonked.
 
G

Guest

Bring up a CLI window, basically by running CMD.EXE at startup.
Run your program from that.  Microsoft tries hard to make running
non-GUI things impossible.

Since I'm sure MS employ some very talented people
I cannot believe they tried to make running non-GUI
things impossible as it is actually quite easy. Even you
managed it! :)
 
T

Tomás Ó hÉilidhe

No problem! All you have to do is fire up the
console window, arrange your windows just so, and then COPY-TYPE
the data from one place to the other. Mouse/Select/^C? Forget it.
Caret/Home/^End? No chance.



If you click the small icon in the top left corner of a command prompt
window, it will bring up a small menu, there's some copy-paste options
in there. If you want to copy text /from/ the console, you have to
select the text and then hit Return to copy it to the clipboard.


And while we're on the subject, why is Windows Explorer always set
up by default with the most brain-damaged options possible (e.g.
hiding part of the file name in case it alarms you)?



Back when there was Windows 95, Windows 98, this "user friendliness"
didn't get in the way too much because it could easily be disabled.
With progressive releases of MS Windows though, the "user
friendliness" has become a hindrance to power users.

Windows Vista is what pushed me over the edge to abandon MS Windows
and take up a new OS. I've been using Linux (the Xubuntu flavour) full-
time for a few weeks now. The switch still hasn't paid off because it
takes a long time to make up for 15 years of familiarity with the
previous OS, but the replacement OS is sufficiently better for me to
put up with it.
 
T

Tomás Ó hÉilidhe

Yes, I know. I don't see what that has to do with copying a pathname
*from* Windows Explorer, however.


If you have the "Address Bar" displayed, you can select the directory
path with the mouse and do Ctrl+C.

View->Toolbars->Address Bar (if memory serves me right)
 
S

soscpd

Hello List

First, Thanks to Larry Jones. Files as parameters will never be the
same on M$ environments.

Here (http://www.microsoft.com/windowsxp/downloads/powertoys/
xppowertoys.mspx) you can find:

Open Command Window Here
This PowerToy adds an "Open Command Window Here" context menu option
on file system folders, giving you a quick way to open a command
window (cmd.exe) pointing at the selected folder.

You can have a "Open Visual Studio Command Prompt Here" too. Found
(and working here) on the friedly google.


Regards
Rafael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top