I'm having trouble passing pointers from a c file to a header file and still being able to call information.
I assume My mistakes are trivial but any help would be greatly appreciated
.c file
Code:
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include "test.h"
typedef struct
{
char type[20];
char value[20];
}Lexeme;
int main(int argc, char *argv[])
{
int scanner(char*, Lexeme *lexeme_pointer);
Lexeme *lexeme_pointer;
//scanner(argv[1], lexeme_pointer);////to be implemented later
scanner("readme.txt", lexeme_pointer);
system("PAUSE");
return 0;
}
int scanner(char* filename, Lexeme *lexeme_pointer)
{
lexInit(filename);
lex(lexeme_pointer);
return 0;
}
.h file
Code:
FILE *readfile;
int lexInit(char* filename)
{
readfile = fopen(filename,"r");
if(readfile == 0)
{
printf("\nfile could not be opened\n\n");
}
else
{
printf("\n File opened\n");
}
return 0;
}
int lex(Lexeme *lexeme_pointer)
{
char ch;
ch = readchar();
lexeme_pointer->type = 'funny';
printf("type = %s",&lexeme_pointer.type);
return 0;
}
///readchar
int readchar()
{
char ch;
ch = fgetc(readfile);
return ch;
}
int pushback()
{
}
int newLexeme(Lexeme *lexeme_pointer)//input string, return a lexeme structure type:NUMBER,VARIABLE data:3, main
{
lexeme_pointer = (Lexeme*)malloc(sizeof(Lexeme));
if(lexeme_pointer == 0)
{
printf("Out of Memory");
}
}
don't worry about the readme file.
It can be literally any file.
My main problem is with the passing of Lexeme *lexeme_pointer to and from the header file and maintaining the values