Witam. Za zadanie mam napisać program zamieniający podany znak na jego postać bitową. Niestety, program nie daje się skompilować. Zlikwidowałem wszystkie błędy, które udało mi się znaleźć. Proszę o pomoc w znalezieniu tych błędów oraz wyjaśnienie, dlaczego jest tam błąd. Kod programu:
Plik1.c:
#include "bitowe.h"
#include <stdio.h>
int main()
{
char c;
int i;
int j;
printf("Podaj jakis znak: \n");
scanf("%d", &u.i);
for (j=3; j>=0; j--)
{
for (i=7; i>=0; i--)
{
printf("%d", get_bit(u.z[j],i));
}
}
return 0;
}
Plik2.h:
#ifndef bitowe_h
#define bitowe_h
int get_bit(char c, int n)
{
union U{char z[4]; int i; float f;}u;
}
#endif
Plik3.c:
int get_bit(char c, int n)
{
int maska=1>>n;
return((maska&c)<<n);
}
A takim komunikatem wita mnie gcc:
In file included from xd.c:1:0:
bitowe.h: In function ‘get_bit’:
bitowe.h:6:37: warning: unused variable ‘u’ [-Wunused-variable]
union U{char z[4]; int i; float f;}u;
^
xd.c: In function ‘main’:
xd.c:10:22: error: ‘u’ undeclared (first use in this function)
scanf("%d", &u.i);
^
xd.c:10:22: note: each undeclared identifier is reported only once for each function it appears in
xd.c:6:14: warning: unused variable ‘c’ [-Wunused-variable]
char c;
^
In file included from xd.c:1:0:
bitowe.h: In function ‘get_bit’:
bitowe.h:7:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^