I wrote an function, which checks, if string of char is palindrome or not.
//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;
}
I also created funs.h
//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);
if(result)
{
printf("Brawo!\n");
}
else
{
printf("Gówno!\n");
}
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
clean:
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 can't see any mistakes. Can you help me fix it?
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-linux-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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.