Pelles C forum

C language => Beginner questions => Topic started by: Raymond4141 on December 15, 2014, 02:20:52 AM

Title: program controlled input and output files.
Post by: Raymond4141 on December 15, 2014, 02:20:52 AM
I need help!
I working on an assignment for class and trying to run this source code!
I keep getting this error ***processed returned 255*** after code crashes.
Here is my source code. I am rather new at Pelles C.

#include <stdio.h>
#define  KMS_PER_MILE 1.609

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

inp = fopen ("b:distance .txt", "r");
outp= fopen ("b: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);
}
Title: Re: program controlled input and output files.
Post by: czerny on December 15, 2014, 08:27:27 AM
Have you seen the blank in your filename?

Use:
"b:\\distance.txt"

You should check if fopen succeded:
inp = fopen ("b:\\distance.txt", "r");
if (inp) {
  // do what you want
} else puts("error opening file!");
Title: Re: program controlled input and output files.
Post by: Raymond4141 on December 16, 2014, 01:09:53 AM
Thanks for replying with help. I did what you said and got the error message could not open file. Could there be some thing wrong with my file name!
Title: Re: program controlled input and output files.
Post by: TimoVJL on December 16, 2014, 09:19:49 AM
Have you really that B-drive ?

You can test opening that file from current directory to test rest of that codeinp = fopen ("distance.txt", "r");
Title: Re: program controlled input and output files.
Post by: Raymond4141 on December 17, 2014, 01:08:44 AM
I tried that and still got the same thing! I wander does it make a difference if I am using Windows 7.