2015-10-14 133 views
-1

好吧,所以我有这样的代码,应该从文件中读取文本,并对这个问题做一些不太重要的计算。当我尝试编译它,我得到这个错误(文件名是pp3.c)在gcc中编译时未定义的引用

/tmp/ccnZaQld.o:pp3.c:(.text+0x5f): undefined refrence to 'sovle' 
/tmp/ccnZaQld.o:pp3.c:(.text+0x5f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol 'solve' 
collect2: error: ld returned 1 exit status 

这里是我的代码

#include <stdio.h> 
#define SIZE 100 

char buff[SIZE][SIZE]; 
int initialize(); 
int read(char*); 
int findstart(); 
int sovle(int,int,int,int); 
int printmaze(); 
int posx, posy, oldposy, oldposx; 


int main(int argc, char* argv[]){ 
    initialize(); 
    read(argv[1]); 
    findstart(); 
    if(sovle(posx, posy,oldposy,oldposx)) 
     printmaze(); 
    else 
     printf("maze is unsolveable"); 
} 

int initialize(){ 
    int i; 
    int m; 
    for(i=0; i<SIZE; i++){ 
     for(m=0; i<SIZE; i++){ 
      buff[i][m]='0'; 
     } 
    } 
} 

int read(char* m88){ 
    FILE* myfile = fopen(m88, "r"); 
    int linenum = 0; 
    while(fgets(buff[linenum], SIZE, myfile)!=NULL){ 
     linenum++; 
    } 
    fclose(myfile); 
} 

int findstart(){ 
    int i,m; 
    for(i=0; i<SIZE; i++){ 
     for(m=0; i<SIZE; i++){ 
      if (buff[i][m]== 'S'){ 
       posx = m; 
       posy = i; 
       oldposy = i; 
       oldposx = m; 
       return 1; 
      } 
     } 
    } 
} 

int solve(int x, int y, int oldx, int oldy){ 
    if(buff[y][x+1] != 'x' && x+1 != oldposx){ 
     if(buff[y][x+1] == '$')return 1; 
     if(solve(y,x+1,y,x)){ 
      buff[y][x+1] = '*'; 
      return 1; 
     } 
    } 
    if(buff[y][x-1] != 'x' && x-1 != oldposx){ 
     if(buff[y][x-1] == '$')return 1; 
     if(solve(y,x-1,y,x)){ 
      buff[y][x-1] = '*'; 
      return 1; 
     } 
    } 
    if(buff[y+1][x] != 'x' && y+1 != oldposy){ 
     if(buff[y+1][x] == '$')return 1; 
     if(solve(y+1,x,y,x)){ 
      buff[y+1][x] = '*'; 
      return 1; 
     } 
    } 
    if(buff[y-1][x] != 'x' && y-1 != oldposy){ 
     if(buff[y-1][x] == '$')return 1; 
     if(solve(y-1,x,y,x)){ 
      buff[y-1][x] = '*'; 
      return 1; 
     } 
    } 
} 

int printmaze(){ 
    int i; 
    while(buff[i][0]!= '0'){ 
     printf("%s", buff[i]); 
     i++; 
    } 
} 
+1

错误信息有点告诉你到底什么是错的。 – teppic

+1

错字作为'解决' – BLUEPIXY

回答

1

您的源错字。 sovlesolve

的一个它的抱怨是在这里:

if(sovle(posx, posy,oldposy,oldposx)) 
    printmaze(); 

它没有帮助,您已经声明了错字作为一个功能:

int findstart(); 
int sovle(int,int,int,int); 
int printmaze(); 
+0

该死的,这是我的一部分真的很愚蠢的错误即时删除此线程,但我非常感谢你花时间来帮助我。 –

相关问题