my code stopped reading in my .txt file

I'm trying to get my code to read in a txt file, it was working yesterday but now when I run it through "start without debugging" it prints out the message I prompted it to but that's it, and no matter what I type in it re-asks the user the same question instead of printing what was written in the txt file.

#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>

void main ()
{
    FILE *file_in;
    char value;
    file_in = NULL;
    char unencrypted [1000];

    while (file_in == NULL)
    {
        printf("Please enter the name of the file you want to open:\n");
        scanf("%s", unencrypted);
        file_in = fopen(unencrypted, "r");
    }

    printf("\n This file consists of the following message: \n");
    while(!feof(file_in))
    {
        value = fgetc(file_in);
        printf("%c", value);
    }

    fclose(file_in);
}

Answers


If it repeatedly asks the user to enter a file name, that means that fopen is returning NULL. You should find out why:

file_in = fopen(unencrypted, "r");
if (file_in == NULL)
    perror(unencrypted);

I don't know what platform you are on, but IDEs typically build release and debug builds to different folders. If you put your test text file in the debug folder, and then do a release build, the file will be unreachable with a relative path.


Need Your Help

How can I use Opus Codec from JavaScript

javascript html5 speech-recognition getusermedia opus

I would like to see if it's possible to have direct access to Opus using getUserMedia or anything similar from the latest browsers.

What is the best alternative for jQuery thickbox

javascript jquery jquery-plugins

As jQuery thickbox is not maintained anymore (as of ThickBox 3.1), what is the best alternative for jQuery thickbox currently available under GPL or similar license. Looks nyromodal is best availab...