Problems with opening .txt files in C - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Problems with opening .txt files in C

I don't understand why this isn't working.

*context* I am trying to open the examdat.txt file to read the file in my program, and then be able to write to the report.txt file. Right now I'm just trying to get the examdat.txt file to open.

[code]#include
#include
// Grade a n-question (5-55) multiple choice exam
//provide feedback for most frequently missed questions
//Take data from file
//examdat.txt
//---------------------------------------------------------------------------
//first line of file contains # of questions on exam follwed by a space
//then an n-character string of correct answers
//--------------------------------------------------------------------------
//write a function fgetAnswers that inputs answers from an open input file.
//Each of the lines that follow contain an interger student ID followed by a space then students answers
// Function fgetAnswers con also be called to input a student's answers.
//-------------------------------------------------------------------------------
//Program is to produce an output file
//Report.txt
//Containing the answer key
//and each student's ID
//and each students score as a percentage






using namespace std;

int report[55];
int main(int argc, char *argv[])
{
FILE *examdat;
FILE *report;
char quest[55];
examdat = fopen("examdat.txt","r");
report = fopen("report.txt","w");



fclose(examdat);
fclose(report);


system("PAUSE");
return EXIT_SUCCESS;
}
[/code]
I don't really know how to get it to open the exam.txt file, any help is appreciated.

Comments

  • WaltPWaltP Posts: 335Member
    1) You need error checking to see if the files are opened.
    2) What folder is the text file living in?
    3) What folder does the .EXE get built into?

    2 & 3 should be the same folder.
  • letswerkitletswerkit Posts: 2Member
    : 1) You need error checking to see if the files are opened.

    I'm not sure if I know what you mean by "error checking"

    : 2) What folder is the text file living in?
    : 3) What folder does the .EXE get built into?
    : 2 & 3 should be the same folder.

    [link=http://imgur.com/A2kvi]imgur.com/A2kvi[/link] <-- Image of all my files (The image poster wasnt working)(I blacked out my name for security purposes.)

    I have all my files in the same folder.

  • WaltPWaltP Posts: 335Member
    : : 1) You need error checking to see if the files are opened.
    :
    : I'm not sure if I know what you mean by "error checking"
    :
    Check for errors. Read your text and/or documentation on the functions used.

    : : 2) What folder is the text file living in?
    : : 3) What folder does the .EXE get built into?
    : : 2 & 3 should be the same folder.
    :
    : [link=http://imgur.com/A2kvi]imgur.com/A2kvi[/link] <-- Image of all
    : my files (The image poster wasnt working)(I blacked out my name for
    : security purposes.)
    :
    : I have all my files in the same folder.

    I'm not looking at images. If you can't post the information I can't read the information.

    Anyway, I already told you what you need.

Sign In or Register to comment.