Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my file pointer causing an undefined symbol error?

Tags:

c

This is my code so far:

#include <stdio.h>

int main(void)
{
    char filename[50];   /* for holding file's name  */
    FILE *fp;            /* fp is the "file pointer" */

    printf("Please enter the name of an input file: ");
    scanf("%s", filename);

    if (!(fp = fopen(filename, "w")))    /*w=write*/
            fprintf(stderr, "unable to open file\a\n");
    else {/* process file */
            fprintf(fp, "Testing...\n");
    }
    return 0;
}

The line

FILE *fp; 
//is giving me an error Undefined Symbol "FILE"

The line

fprintf(stderr, "unable to open file\a\n"); 
//is giving me an error Undefined Symbol "stderr"

I thought these keywords were standard C/C++? Why are they giving me errors?

like image 862
theUser Avatar asked Oct 27 '25 07:10

theUser


1 Answers

Did you #include <stdio.h>? Also your declaration of main() is incorrect. It should return int, not void.

And no, FILE is not a keyword in either C or C++. Its declaration is in <stdio.h>.

like image 160
Armen Tsirunyan Avatar answered Oct 29 '25 23:10

Armen Tsirunyan