For some reason my following program won't compile, I cant really find out why. I put the method between comments so the error isn't located there I guess it might have something to do with the typedef.
#include <stdio.h>
#include <stdlib.h>
typedef unsigned char uchar;
typedef unsigned int uint;
uchar register(uint);
int main() {
uint data = 819;
/*
printf("%c", register(data));
*/
}
uchar register(uint data) {
/*
uchar reg = 0;
while(data != 0) {
if(reg&0x80 == 1) {
reg=reg<<1;
reg += data&0x1;
data = data>>0;
reg = reg ^ 81;
}
else {
reg<<1;
reg += data&0x1;
data = data>>0;
}
}
return reg;
*/
}
Errors:
[Note] previous declaration of 'uint' was here
[Error] expected ')' before 'data'
[Error] expected expression before 'register'
after all the coding errors were corrected, it compiled with no errors.
note that no changes were made to the typedef statements.
#include <stdio.h>
#include <stdlib.h>
typedef unsigned char uchar;
typedef unsigned int uint;
uchar Myregister(uint);
int main()
{
uint data = 819;
printf("%c", Myregister(data));
return(0);
}
uchar Myregister(uint data)
{
uchar reg = 0;
while(data != 0)
{
if( (reg&0x80) == 1)
{
reg=reg<<1;
reg += data&0x1;
data = data>>1;
reg = reg ^ 81;
}
else
{
reg = reg<<1;
reg += data&0x1;
data = data>>1;
}
}
return reg;
}