Advertisement

07.08.2008 at 03:39PM PDT, ID: 23548582
[x]
Attachment Details

fopen command and file IO in unix

Asked by jeffiepoo in C Programming Language

Tags: Unix, Open SUSE 10.2, C scripting

I need this question answered to HELP do my homework. I AM NOT asking anyone to do it for me. Say I have the following code: (this is just a function definition at the bottom)(AND the string filename[81] has already been initiated in the main() function)

void get_filename(char filename[81]){
  printf("What is the name of the file?\n");
  scanf("%s", filename);
   }

So far, this function will read in a string that is a filename. I know that I can open a file with the following code at the end of this function:

FILE * input_file;
input_file = fopen("hello.txt","r");

Here is my problem, I need to know how to replace "hello.txt" with the string that the user just entered. (via: the filename[81] string)

I have already tried replacing "hello.txt" with "filename" "&filename" and "filename[ ]"
How would I use the fopen command to open the file specified in the string?Start Free Trial
 
 
[+][-]07.08.2008 at 03:41PM PDT, ID: 21958969

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C Programming Language
Tags: Unix, Open SUSE 10.2, C scripting
Sign Up Now!
Solution Provided By: Infinity08
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.08.2008 at 09:11PM PDT, ID: 21960558

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628