Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5430
Number of posts: 16951

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Problems with opening .txt files in C Posted by letswerkit on 5 Oct 2012 at 12:49 PM
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.

#include <cstdlib>
#include <iostream>
// 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;
}

I don't really know how to get it to open the exam.txt file, any help is appreciated.

Report
Re: Problems with opening .txt files in C Posted by WaltP on 5 Oct 2012 at 1:01 PM
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.
Report
Re: Problems with opening .txt files in C Posted by letswerkit on 6 Oct 2012 at 9:19 AM
: 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.

imgur.com/A2kvi <-- 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.

Report
Re: Problems with opening .txt files in C Posted by WaltP on 7 Oct 2012 at 7:33 PM
: : 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.
:
: imgur.com/A2kvi <-- 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.




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.