program controlled input and output files.

Started by Raymond4141, December 24, 2014, 06:06:24 PM

Previous topic - Next topic

Raymond4141

I am writing a program controlled file for pelles c and when I run it I get this error message ***processed returned 255***. I am running windows 7 as my os.

frankie

Sorry we miss the crystal ball here...  ;D
Post the code.
Merry Xmas
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Raymond4141

Sorry bout that,
Here is the code:
      #Include <stdio.h>
      #define KMS_PER_MILE  1.609

int
main (void)
{
    double miles,kms;
     FILE   *inp,*outp;

inp = fopen ("c: distance.txt", "r");
outp = fopen ("c: distout.txt", "w");

fscanf (inp, "%lf", &miles);
fprintf(outp, "The distance in miles is %.2f.\n", miles);

kms = KMS_PER-MILE * miles;

fprintf (outp, "That equals %.2f kilometers.\n", kms);

fclose(inp);
fclose (outp);

return (0);
}


The code when ran crashes and outputs error message ***process returns 255***.
Thanks for any help you can give in advance.

frankie

Just for Xmas the solution for an assignement  ;D


#include <stdio.h>
#define KMS_PER_MILE  1.609

int main (void)
{
double miles,kms;
FILE   *inp,*outp;

inp = fopen ("distance.txt", "r");
if (!inp) //Chek if opening was ok!!!!
{
printf("Can't open input file!\nProgram will terminate\n");
return -1;
}

outp = fopen ("distout.txt", "w");
if (!outp) //Chek if opening was ok!!!!
{
printf("Can't open output file!\nProgram will terminate\n");
return -1;
}

fscanf (inp, "%lf", &miles);
fprintf(outp, "The distance in miles is %.2f.\n", miles);

kms = KMS_PER_MILE * miles;

fprintf (outp, "That equals %.2f kilometers.\n", kms);

fclose(inp);
fclose (outp);

return (0);
}


If you really wanto open files on C: root don't leave spaces!
inp = fopen ("c:distance.txt", "r");
Not
inp = fopen ("c: distance.txt", "r");
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Bitbeisser

Quote from: frankie on December 30, 2014, 11:24:46 PM
Just for Xmas the solution for an assignement  ;D


#include <stdio.h>
#define KMS_PER_MILE  1.609

int main (void)
{
double miles,kms;
FILE   *inp,*outp;

inp = fopen ("distance.txt", "r");
if (!inp) //Chek if opening was ok!!!!
{
printf("Can't open input file!\nProgram will terminate\n");
return -1;
}

outp = fopen ("distout.txt", "w");
if (!outp) //Chek if opening was ok!!!!
{
printf("Can't open output file!\nProgram will terminate\n");
return -1;
}

fscanf (inp, "%lf", &miles);
fprintf(outp, "The distance in miles is %.2f.\n", miles);

kms = KMS_PER_MILE * miles;

fprintf (outp, "That equals %.2f kilometers.\n", kms);

fclose(inp);
fclose (outp);

return (0);
}


If you really wanto open files on C: root don't leave spaces!
inp = fopen ("c:distance.txt", "r");
Not
inp = fopen ("c: distance.txt", "r");
Close but no cigar!
This will (try to) open the file in the current folder on the C: drive, most likely that of the C compiler installation.

To access a file in the root of the C: drive you have to properly use a "\" after the drive designation "C:", so the right instruction would beinp = fopen ("c:\distance.txt", "r");

Ralf  ;)

Raymond4141

I tried all of them and the out put reads as follows:  Can't open input file and program will terminate.

jj2007

Quote from: Bitbeisser on December 31, 2014, 02:17:39 AMTo access a file in the root of the C: drive you have to properly use a "\" after the drive designation "C:", so the right instruction would beinp = fopen ("c:\distance.txt", "r");

Are you sure you get c:\distance.txt with a single backslash?

TimoVJL

Previous topic was already here and a stupid question:
Have you that 'distance.txt' anywhere ?

If it is in C: root then this may work too:
inp = fopen ("c:/distance.txt", "r");
May the source be with you

frankie

"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Bitbeisser

Quote from: jj2007 on December 31, 2014, 03:44:50 AM
Quote from: Bitbeisser on December 31, 2014, 02:17:39 AMTo access a file in the root of the C: drive you have to properly use a "\" after the drive designation "C:", so the right instruction would beinp = fopen ("c:\distance.txt", "r");

Are you sure you get c:\distance.txt with a single backslash?
Oops  :-[, of course not. Just had been working all day in Pascal, so I missed that. It needs to be of courseinp = fopen ("c:\\distance.txt", "r");

Ralf

Raymond4141

I found and fixed the problem! All the help I got here was tremendous! The problems was with my computer. My hard drive was corrupted. That's why I was getting the *** processed returned 255***.
Once again thanks everyone for there help! Got a an 85% on my assignment!