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…
filenameis variable , why are you passing it in""double quotes.Try something like this below:
now use
I think this should work.
Also you need to check the
fpas