Home C palindrom program - undefined reference to main
Reply: 1

C palindrom program - undefined reference to main

Mateusz Trzeciak
Mateusz Trzeciak Published in 2017-12-07 12:03:42Z

I wrote an function, wich checks, if string of char is palindrom or not.


#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')

    end = length - 1;
    middle = length;

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

I also created funs.h

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

Now, I'm trying to use this function in my main function

#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);
    return 0;

I also created makefile:

# 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

rm -f main *.o *~

Everything seems fine and works in single file, but when I try to compile them separately they "don't see" each other. Makefile also seems to work badly, but I cant see any mistakes. Can you help me fix it?

hymie Reply to 2017-12-07 14:15:26Z

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

Did you actually look at line 15 of your makefile? Notice that it's flush against the margin instead of indented by a tab character.

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'

Indeed, your pan.c does not have a main() function. So don't try to compile it by itself. How about

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

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.303895 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO