I am attempting to recompile a C program i programmed on linux. These are the errors i recieve:

 c:\users\dsu\dropbox\codes\c\gamereedtucker\main.c(28): error C2275: 'FILE' : illegal use of this type as an expression
           c:\program files\microsoft visual studio 10.0\vc\include\stdio.h(66) : see declaration of 'FILE'
 c:\users\dsu\dropbox\codes\c\gamereedtucker\main.c(28): error C2065: 'sy' : undeclared identifier
 c:\users\dsu\dropbox\codes\c\gamereedtucker\main.c(29): error C2065: 'sy' : undeclared identifier
 c:\users\dsu\dropbox\codes\c\gamereedtucker\main.c(29): warning C4047: '=' : 'int' differs in levels of indirection from 'FILE *'
 c:\users\dsu\dropbox\codes\c\gamereedtucker\main.c(48): error C2065: 'sy' : undeclared identifier
 c:\users\dsu\dropbox\codes\c\gamereedtucker\main.c(48): warning C4047: 'function' : 'FILE *' differs in levels of indirection from 'int'
 c:\users\dsu\dropbox\codes\c\gamereedtucker\main.c(48): warning C4024: 'fprintf' : different types for formal and actual parameter 1
c:\users\dsu\dropbox\codes\c\gamereedtucker\main.c(50): error C2065: 'sy' : undeclared identifier
c:\users\dsu\dropbox\codes\c\gamereedtucker\main.c(50): warning C4047: 'function' : 'FILE *' differs in levels of indirection from 'int'
c:\users\dsu\dropbox\codes\c\gamereedtucker\main.c(50): warning C4024: 'RoomOne' : different types for formal and actual parameter 3
c:\users\dsu\dropbox\codes\c\gamereedtucker\main.c(55): error C2065: 'sy' : undeclared identifier
c:\users\dsu\dropbox\codes\c\gamereedtucker\main.c(55): warning C4047: 'function' : 'FILE *' differs in levels of indirection from 'int'
c:\users\dsu\dropbox\codes\c\gamereedtucker\main.c(55): warning C4024: 'fprintf' : different types for formal and actual parameter 1
c:\users\dsu\dropbox\codes\c\gamereedtucker\main.c(64): error C2065: 'sy' : undeclared identifier
c:\users\dsu\dropbox\codes\c\gamereedtucker\main.c(64): warning C4047: 'function' : 'FILE *' differs in levels of indirection from 'int'
c:\users\dsu\dropbox\codes\c\gamereedtucker\main.c(64): warning C4024: 'fprintf' : different types for formal and actual parameter 1
c:\users\dsu\dropbox\codes\c\gamereedtucker\main.c(67): error C2065: 'sy' : undeclared identifier
c:\users\dsu\dropbox\codes\c\gamereedtucker\main.c(67): warning C4047: 'function' : 'FILE *' differs in levels of indirection from 'int'
c:\users\dsu\dropbox\codes\c\gamereedtucker\main.c(67): warning C4024: 'fclose' : different types for formal and actual parameter 1
  commands.c
c:\users\dsu\dropbox\codes\c\gamereedtucker\commands.c(13): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
          c:\program files\microsoft visual studio 10.0\vc\include\stdio.h(304) : see declaration of 'scanf'
c:\users\dsu\dropbox\codes\c\gamereedtucker\commands.c(26): warning C4047: 'function' : 'FILE **' differs in levels of >indirection from 'char [10]'
c:\users\dsu\dropbox\codes\c\gamereedtucker\commands.c(26): warning C4024: 'fopen_s' : different types for formal and actual parameter 1
c:\users\dsu\dropbox\codes\c\gamereedtucker\commands.c(26): error C2198: 'fopen_s' : too few arguments for call
c:\users\dsu\dropbox\codes\c\gamereedtucker\commands.c(26): warning C4047: '=' : 'FILE *' differs in levels of indirection from 'errno_t'
c:\users\dsu\dropbox\codes\c\gamereedtucker\commands.c(27): error C2143: syntax error : missing ';' before 'type'
c:\users\dsu\dropbox\codes\c\gamereedtucker\commands.c(28): error C2065: 'done' : undeclared identifier
c:\users\dsu\dropbox\codes\c\gamereedtucker\commands.c(33): error C2143: syntax error : missing ';' before 'type'
c:\users\dsu\dropbox\codes\c\gamereedtucker\commands.c(34): error C2065: 'end' : undeclared identifier
c:\users\dsu\dropbox\codes\c\gamereedtucker\commands.c(36): error C2065: 'done' : undeclared identifier

I did all the errors i could fix already. this is the main.c page from my code, if you want commands.c I can add that aswell.

I would really just like this part of my code to compile so i can fix the rest

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "player.h"
#include "other.h"

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

    dug * one = malloc(sizeof(dug)*1);
    player * us = malloc (sizeof(player)*1);
    us->cheat = malloc(sizeof(int)*1);
    *us->cheat = 0;

    /*if(argv[1] != NULL);
    {
        int cheat =0;
        FILE * CHEAT;
        CHEAT = fopen_s(argv[1], "r");
        fscanf(CHEAT,"%d",&cheat);
        if(cheat == 25)
        {
            printf("you activated cheat codes\n");
            *us->cheat = 1;
        }
        fclose(CHEAT);
    }*/
    FILE *sy;
    sy = fopen("story.txt","a");

    us -> name = malloc (sizeof(char)*40);
    us -> HP = malloc (sizeof(int)*1);
    us->dir = malloc(sizeof(int)*1);
    us->help = malloc(sizeof(int)*1);

    one->torch = malloc(sizeof(int)*1);
    *one->torch = 1;

    *us->HP = 10;
    *us->dir = 3;//1 north, 2 east,3 south,4 west
    *us->help = 0;

    one->WIN = malloc(sizeof(int)*1);
    *one->WIN = 0;

    printf(" What is your name:");
    scanf("%s", us -> name);
    fprintf(sy,"The journals of %s\n", us->name);

    RoomOne(us,one,sy);

    if(*one->WIN == 0)
    {
        printf("Game Over,%s\n",us->name);
        fprintf(sy,"\tLast entry, %s\n",us->name);
        if(*us->cheat == 1)
        {
            printf("winners never cheat, and cheater's never win.\n");
        }
    }
    if(*one->WIN == 1)
    {
        printf("You have escaped the dark, Now face the light.\n");
        fprintf(sy,"you have won the game, %s.\n",us->name);
    }

    fclose(sy);
    return 0;
}

Edited 3 Years Ago by totalwar235

Were you perchance compiling as C99 or C++ on Linux? Because Visual Studio doesn't yet support C99's mixing of declarations and executable code unless you compile as C++.

All of your other main.c errors stem from the first error. Once you move all declarations to the top of the scope, that error will go away. You didn't show the commands.c file, so I can't comment on it.

Also note that warning C4996 is bullshit and can be ignored in all cases. Feel free to disable it entirely from the project configuration.

it was probably c99, because im very sure we were not programming in c++. this was a final project from a college class i did and they never told us what kind of c we programmed in.

i thought all the errors was from the first one, but im not sure how i would fix that one as of now.

and ill keep that in mind about c4996, thank you

but im not sure how i would fix that one as of now.

Move all declarations to the top of the current scope. For example with your main.c:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "player.h"
#include "other.h"

int main(int argc, char const *argv[])
{
    dug * one = malloc(sizeof(dug) * 1);
    player * us = malloc(sizeof(player) * 1);
    FILE *sy;

    us->cheat = malloc(sizeof(int)* 1);
    *us->cheat = 0;

    sy = fopen("story.txt", "a");

    us->name = malloc(sizeof(char)* 40);
    us->HP = malloc(sizeof(int)* 1);
    us->dir = malloc(sizeof(int)* 1);
    us->help = malloc(sizeof(int)* 1);

    one->torch = malloc(sizeof(int)* 1);
    *one->torch = 1;

    *us->HP = 10;
    *us->dir = 3;//1 north, 2 east,3 south,4 west
    *us->help = 0;

    one->WIN = malloc(sizeof(int)* 1);
    *one->WIN = 0;

    printf(" What is your name:");
    scanf("%s", us->name);
    fprintf(sy, "The journals of %s\n", us->name);

    RoomOne(us, one, sy);

    if (*one->WIN == 0) {
        printf("Game Over,%s\n", us->name);
        fprintf(sy, "\tLast entry, %s\n", us->name);
        if (*us->cheat == 1) {
            printf("winners never cheat, and cheater's never win.\n");
        }
    }
    if (*one->WIN == 1) {
        printf("You have escaped the dark, Now face the light.\n");
        fprintf(sy, "you have won the game, %s.\n", us->name);
    }

    fclose(sy);
    return 0;
}

Easy peasy. Prior to C99, C doesn't allow declarations to be mixed with executable code; declarations always come first.

thank you for the help. i never got that error working on linux but now it makes sense why people say to put variables at the top of the functions.

This question has already been answered. Start a new discussion instead.