Results 1 to 3 of 3
Let me say that I am a newb to the world of Linux/Unix/Fedora. I am in a Fedora programming class and I am trying to run/create a File Copy Program ...
- 09-28-2008 #1Just Joined!
- Join Date
- Sep 2008
- Location
- Buffalo, NY
- Posts
- 25
Trying to run/create a File Copy Program
Let me say that I am a newb to the world of Linux/Unix/Fedora. I am in a Fedora programming class and I am trying to run/create a File Copy Program through the Terminal. I have the code completed but I am having a hard time running the program because the program can't find my input or output files and it is really frustrating. I have created two text files that are located in /home/software/lab3a.txt and /home/software/lab3ab.txt
I hope I can get a quick answer for this so I can continue on with my other programming assignments.
My question is: Where would I place the lab3a.txt and lab3ab.txt in the code below
Thanks again - I hope I will be learning much more here
Code:
#include <stdio.h>
#include <stdlib.h>
main()
{
FILE *input_file,
*output_file;
char input_name[15],
output_name[15];
int c;
puts("*** File Copy Program ***" );
printf("Enter the name of the input file :");
scanf("%s", input_name);
printf("Enter the name of the output file :");
scanf("%s", output_name);
input_file = fopen(input_name, "r");
if (input_file == NULL)
{
puts("*** Can't open input file ***");
exit(0);
}
output_file = fopen(output_name, "w");
if (output_file == NULL)
{
puts("*** Can't open output file ***");
exit(0);
}
while ((c = getc(input_file)) != EOF)
putc(c, output_file);
fclose(input_file);
fclose(output_file);
}
- 09-28-2008 #2Just Joined!
- Join Date
- Dec 2007
- Posts
- 12
The code works fine. It's interactive. Here is my experience with the program and the bold is what I typed in:
Make sure the files exist too! This program was run with both txt files in the same directory as the executable.Code:$./a.out *** File Copy Program *** Enter the name of the input file :input.txt Enter the name of the output file :output.txt
- 09-28-2008 #3Just Joined!
- Join Date
- Sep 2008
- Location
- Buffalo, NY
- Posts
- 25
Thanks for the assistance. Everything is working now



Reply With Quote