2017-12-07 7 views
-1

char 문자열이 palindrom인지 아닌지를 확인하는 함수를 작성했습니다.C palindrom 프로그램 - 메인에 대한 정의되지 않은 참조

# Makefile 

all: main 

main: main.o pan.o 
    clang -o main main.o pan.o 

main.o: main.c 
    clang -c main.c 

pan.o: pan.c 
    clang -c pan.c 

clean: 
rm -f main *.o *~ 
:

//pan.c 

#include <stdbool.h> 
#include "funs.h" 
#include <stdio.h> 
#include <string.h> 

bool palindrom(char napis[]) 
{ 
    int begin, middle, end, length = 0; 

    while(napis[length] != '\0') 
     length++; 

    end = length - 1; 
    middle = length; 

    for (begin = 0; begin < middle; begin++) 
     { 
     if(napis[begin] != napis[end]) 
     { 
      return false; 
      break; 
     } 
     end--; 
     } 
     if(begin == middle) 
     return true; 
} 

가 나는 또한 지금

//funs.h 
#include <stdbool.h> 
bool palindrom(); 

funs.h 만들어 내 주요 기능에

#include <stdbool.h> 
#include <stdio.h> 
#include <string.h> 
#include "funs.h" 


int main() 
{ 
    char text[100]; 
    bool result; 

    printf("Enter an char: "); 
    scanf("%s", text); 
    result = palindrom(text); 
    if(result) 
    { 
     printf("Brawo!\n"); 
    } 
    else 
    { 
     printf("Gówno!\n"); 
    } 
    return 0; 
} 

I도 만들어 메이크이 기능을 사용하기 위해 노력하고있어

모든 항목이 정상적으로 작동하며 단일 파일을 만들지 만 개별적으로 컴파일하려고하면 서로 보지 못합니다. Makefile도 나쁘게 작동하는 것처럼 보이지만 나는 실수를 볼 수 없습니다. 내가 고칠 수있게 도와 줄 수 있니?

+0

'부울 회문()는 어떻게,'모든 int''기본적으로 매개 변수의 수를 수신 할 수있는 기능을 정의합니다. 그래서 잘못되었습니다 ... –

+0

'bool palindrom(); 선언문에 놓친 부분이 없으므로'bool palindrom (char *);'이어야합니다. – rafix07

+0

@MateuszTrzeciak : _but 별도로 컴파일하려고하면 컴파일 할 때 발생하는 오류는 무엇입니까? –

답변

4

When I try "make" command it returns "makefile:15: *** missing separator. Stop." comment and do nothing.

실제로 메이크 파일의 15 번째 줄을 보셨습니까? 탭 문자가 들여 쓰기되는 대신 여백과 일치합니다.

When I'm compiling pan.c with "clang pan.c -Wall --pedantic -std=c11 -o pan" command: 1 warning generated. /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-l‌​inux-gnu/crt1.o: In function _start': (.text+0x20): undefined reference to main'

실제로 pan.c에는 main() 함수가 없습니다. 그러니 스스로 컴파일하려고하지 마십시오. 대한

clang main.c pan.c -Wall --pedantic -std=c11 -o pan