Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8944967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:08:25+00:00 2026-06-15T12:08:25+00:00

So for this assignment I am supposed to read a file, and do things

  • 0

So for this assignment I am supposed to read a file, and do things with the content. Right now I just want to be able to open the file, read it and print out how many lines it has. I believe I have the proper code to do so, but I have no idea how to “read” or connect to the file outside of my program! I am using the

FILE *fp = NULL; 
fp = fopen ();

part right? And that is how to open / connect to a file? But not sure what this does, and how it can connect to a file outside of the program. To read the file I have the user input their text file like

printf ("Enter the name of the data file: ");
scanf ("%[^\n]", &filename);

And then to read that I put

fp = fopen("&filename", "r");

but this doesn’t seem right and it doesn’t work. Can anyone explain what I am doing wrong, and how I can read a file that a user inputs? I am in an SSH matrix group if that makes sense, Like I log onto putty using an ssh terminal? Not sure how to explain it, but it’s my schools online SSH thing…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:08:26+00:00Added an answer on June 15, 2026 at 12:08 pm
    fp = fopen("&filename", "r");
    

    filenameis variable , why are you passing it in "" double quotes.

    Try something like this below:

    char filename[50]; // need a character array or buffer to hold the filename
    
    printf ("Enter the name of the data file: ");
    scanf ("%[^\n]", filename);   // no & operator
    

    now use

    fp = fopen(filename, "r");   // filename variable should contain complete path 
    
                                  //with the actual file name
    

    I think this should work.

    Also you need to check the fp as

    if(fp == NULL)   // It's always a safe way to proceed
       printf("Error in file opening\n");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a homework assignment I need to read a file in this format: Miller
This is a homework assignment, just for all that want to know. I'm writing
I've been working on this assignment, where I need to read in records and
So for an assignment I have to read from a input file that is
This is part of an assignment. Everything that's supposed to work, already works, but
So I have this assignment where I read in 1 line at a time
I having some trouble with an APCS assignment. The program is supposed to read
I have this assignment to read, write, enable cookies so that the username will
Current assignment needs me to write a program to read a file with instructions
I'm working on an assignment right now where we create our own basic, dynamically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.