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);
}