Thread: Tons of errors: File undeclared (first use in this function)

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    13

    Tons of errors: File undeclared (first use in this function)

    Hi everyone,

    I am sort of newish to C. And i am writing a type of
    "self modifying code". I am trying to read in the source file
    and using fgets(), store each line inside a linked list
    using struct so i can parse it and modify it later.
    But i am getting a bunch of weird errors.

    "File undeclared (first use in this function)"
    (points to line that says "
    Code:
    File *fp=fopen("thisFile.c","rw");
    ")

    I can't figure out why i am getting this file undeclared error even though i included the stdio.h and declared the FILE
    And also on the same line, the compiler is complaining about some undeclared identifier

    Each undeclared identifier is reported only once
    for each function it appears in.
    Any help would be much appreciated. Thank you




    Code:
    #include <stdint.h>
    #include <stdio.h>
    #include <string.h>
    
    typedef struct node{
    	struct node *next;
    	char *line;
    	
    } node_t;
    
    ....
    
    modify(){
     int i=0;
     char* buff;
     char buffer[128];
     File *fp=fopen("thisFile.c","rw");
     
     
     node_t str_node = NULL;
     node_t head = NULL;
     
    while(fgets(buffer, sizeof(buffer), fp)!=NULL) 
    {
    	node_t *temp1;
    	temp1 = (node*) malloc(sizeof(node));
    	//temp1->line = *buffer;
    	temp1->next = head;
    	head = temp1;
    	while(temp1->next != NULL)
    	{
    		temp1 = temp1->next;
    	}
    	//str_node.line = *buffer;
    	node_t *temp;
    	temp=(node*) malloc(sizeof(node));
    	temp->line = *buffer;
    	temp->next = NULL;
    	temp1-> next = temp;
    }
      fclose(fp);
    }

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    FYI: C is case sensitive.

    FILE is not the same as File.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    13
    Thank you very much stahta01 that resolved the issue. I was banging my head for hours- and it turns out to be a simple typo....
    Again thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tons of File/Directory Manipulation.
    By Brandon Smith in forum C Programming
    Replies: 1
    Last Post: 03-03-2012, 04:56 PM
  2. Undeclared first use of function
    By TheXx11 in forum C++ Programming
    Replies: 3
    Last Post: 11-20-2010, 01:15 AM
  3. undeclared (first use in this function)
    By chocolatecake in forum C Programming
    Replies: 2
    Last Post: 03-31-2009, 09:07 AM
  4. 'NULL' undeclared (first use this function)
    By sirconnorstack in forum C++ Programming
    Replies: 32
    Last Post: 06-21-2008, 04:35 AM
  5. undeclared (first use this function)
    By SC_Gordy in forum C++ Programming
    Replies: 6
    Last Post: 03-28-2005, 05:53 PM