NO

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

Raymond4141

  • Guest
program controlled input and output files.
« on: December 24, 2014, 06:06:24 PM »
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.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2097
Re: program controlled input and output files.
« Reply #1 on: December 24, 2014, 08:42:53 PM »
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

  • Guest
Re: program controlled input and output files.
« Reply #2 on: December 30, 2014, 08:27:12 PM »
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.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2097
Re: program controlled input and output files.
« Reply #3 on: December 30, 2014, 11:24:46 PM »
Just for Xmas the solution for an assignement  ;D

Code: [Select]
#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!
Code: [Select]
inp = fopen ("c:distance.txt", "r");Not
Code: [Select]
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

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: program controlled input and output files.
« Reply #4 on: December 31, 2014, 02:17:39 AM »
Just for Xmas the solution for an assignement  ;D

Code: [Select]
#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!
Code: [Select]
inp = fopen ("c:distance.txt", "r");Not
Code: [Select]
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 be
Code: [Select]
inp = fopen ("c:\distance.txt", "r");
Ralf  ;)

Raymond4141

  • Guest
Re: program controlled input and output files.
« Reply #5 on: December 31, 2014, 03:25:09 AM »
I tried all of them and the out put reads as follows:  Can't open input file and program will terminate.

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: program controlled input and output files.
« Reply #6 on: December 31, 2014, 03:44:50 AM »
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 be
Code: [Select]
inp = fopen ("c:\distance.txt", "r");

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

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: program controlled input and output files.
« Reply #7 on: December 31, 2014, 09:47:11 AM »
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:
Code: [Select]
inp = fopen ("c:/distance.txt", "r");
May the source be with you

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2097
Re: program controlled input and output files.
« Reply #8 on: December 31, 2014, 09:43:53 PM »
He forgot to create the input file  ;)
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: program controlled input and output files.
« Reply #9 on: January 01, 2015, 02:09:19 AM »
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 be
Code: [Select]
inp = 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 course
Code: [Select]
inp = fopen ("c:\\distance.txt", "r");
Ralf

Raymond4141

  • Guest
Re: program controlled input and output files.
« Reply #10 on: January 04, 2015, 10:49:24 PM »
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!