NO

Author Topic: program controlled input and output files.  (Read 3840 times)

Raymond4141

  • Guest
program controlled input and output files.
« 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);
}

czerny

  • Guest
Re: program controlled input and output files.
« Reply #1 on: December 15, 2014, 08:27:27 AM »
Have you seen the blank in your filename?

Use:
Code: [Select]
"b:\\distance.txt"
You should check if fopen succeded:
Code: [Select]
inp = fopen ("b:\\distance.txt", "r");
if (inp) {
  // do what you want
} else puts("error opening file!");
« Last Edit: December 15, 2014, 08:30:15 AM by czerny »

Raymond4141

  • Guest
Re: program controlled input and output files.
« Reply #2 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!

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: program controlled input and output files.
« Reply #3 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 code
Code: [Select]
inp = fopen ("distance.txt", "r");
May the source be with you

Raymond4141

  • Guest
Re: program controlled input and output files.
« Reply #4 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.