1 Replies - 192 Views - Last Post: 22 January 2013 - 04:06 AM Rate Topic: -----

#1 jaysonlagare  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 13-May 09

Fixing Linker Errror in C

Posted 22 January 2013 - 02:03 AM

Hello everyone. I have a problem with my c program. There's no error in compiling the program but when I run it, I got stuck with this error:

linker error: Undefined symbol Gen_token(char near*, char[10]near*) in module E:OPTIMIZED.CPP

Can someone help me to fix it? thanks a lot!

/*******************************************************************
Program for Code Optimization Technique of Constant Folding
*******************************************************************/
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#include<ctype.h>
struct ConstFold
{
char new_Str[10];
char str[10];
}Opt_Data[20];

void ReadInput(char Buffer[],FILE *Out_file);
int Gen_token(char str[],char Tokens[][10]);
int New_Index=0;
int main()
{
FILE *In_file,*Out_file;
char Buffer[100],ch;
int i=0;
In_file = fopen("d:\\code.txt","r");
Out_file = fopen("d:\\output.txt","w");
clrscr();
while(1)
{
ch = fgetc(In_file);
i=0;
while(1)
{
if(ch == '\n')
break;
Buffer[i++]=ch;
ch = fgetc(In_file);
if(ch == EOF)
break;
}//End while
if(ch ==EOF)
break;
Buffer[i]='\0';
ReadInput(Buffer, Out_file);//writing to the output file
}//End while
return 0;
}//End main

void ReadInput(char Buffer[],FILE *Out_file)
{
char temp[100],Token[10][10];
int n,i,j,flag=0;
strcpy(temp,Buffer);
n= Gen_token(temp,Token);
for(i=0;i<n;i++)
{
if(!strcmp(Token[i],"="))
{
if(isdigit(Token[i+1][0])||Token[i+1][0] == '.')
{
/*If yes then saving that number and its variable
In the Opt_Data array*/
flag=1;
strcpy(Opt_Data[New_Index].new_Str,Token[i-1]);
strcpy(Opt_Data[New_Index++].str,Token[i+1]);
}//End if
}//End if
}//End for

if(!flag)
{
for(i=0;i<New_Index;i++)
{
for(j=0;j<n;j++)
{
if(!strcmp(Opt_Data[i].new_Str,Token[j]))
strcpy(Token[j],Opt_Data[i].str);
}//End for
}//End for
}//End if
fflush(Out_file);
strcpy(temp,"");
for(i=0;i<n;i++) /*Loop to obtain complete tokens*/
{
strcat(temp,Token[i]);
if(Token[i+1][0]!=','||Token[i+1][0] != ',')
strcat(temp," ");
}//End for
strcat(temp,"\n\0");
fwrite(&temp,strlen(temp),1,Out_file);
}

/*The Gen_Token function breaks the input line into tokens*/
int Gen_Token(char str[], char Token[][10])
{
int i=0,j=0,k=0;
while(str[k]!='\0')
{
j=0;
while(str[k] ==' '|| str[k] =='\t')
k++;
while(str[k]!=' '&& str[k]!='\0'&& str[k]!= '=' && str[k] != '/'&& str[k]!= '+' && str[k] != '-'&& str[k]!= '*' && str[k] != ',' && str[k]!= ';')
Token[i][j++] = str[k++];
Token[i++][j] = '\0';
if(str[k] == '='|| str[k] == '/'|| str[k] == '+'|| str[k]== '-'|| str[k] == '*'|| str[k] == '*'|| str[k] == ','||str[k] == ';')
{
Token[i][0] = str[k++];
Token[i++][1] = '\0';
}//End if
if (str[k] == '\0')
break;
}//End while
return i;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Fixing Linker Errror in C

#2 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 769
  • View blog
  • Posts: 2,246
  • Joined: 20-March 10

Re: Fixing Linker Errror in C

Posted 22 January 2013 - 04:06 AM

You declare your function

as

int Gen_token(char str[],char Tokens[][10]);

you call it as

Gen_token

but you implement it as

int Gen_Token(char str[],char Tokens[][10]);


C/C++ is case sensitve.

Snoopy.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1