Dustin Brown
Dustin Brown

Reputation: 23

C: fopen(); is producing unhandled exception error

if ((fp = fopen(argv[2], "r")) == NULL){
    printf("Failed to load file");
}

I'm pretty new to C, I'm not sure why this is producing an error. It's opening a new window and saying

unhandled exception error. 

What does this error mean? I am using Visual Studio 2013

Complete program:

#include <stdio.h>
#include <string.h>

#pragma warning (disable:4996);

FILE * fopen(char *filename,char *access);


int main(int argc, char argv[]){

    FILE *fp = NULL;
    char fileContents[100] = { 0 };


    if ((fp = fopen(argv[2], "r")) == NULL){
        printf("Failed to load file");
    }

}

Upvotes: 2

Views: 1812

Answers (1)

Bhargav Rao
Bhargav Rao

Reputation: 52181

Try changing char argv[] to char *argv[]

Upvotes: 1

Related Questions