questions about c programming language

Hello
I read K&R at one point in my life but I forgot it.

http://www.compileonline.com/compile_c_online.php
Here is the question:
Is this something an online compiler doesn’t support or is it my programming problem?
I am trying to work out an algorithm to use in my Arduino project.
I want to manipulate bits and re-learn how to use pointers.
C offers no way of creating standalone 1 bit Boolean variable.
I am coincidentally using 8 elements that need to report either 0 or 1.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

  main()
{
    char buffer [33];
    unsigned int a=0b00001101;
    unsigned int b=0b11111111,c,d;
    c = a>>2;
    d=~a;
    itoa (d,buffer,2);
    printf("PROGRAM output: %u  %u  %u  %s <<<",a,b,c,buffer);
    
}

C offers bitfields, but they are often more trouble than they are worth. In practice a single byte boolean variable works well, unless you need millions of them.

VT91:
Here is the question:
Is this something an online compiler doesn’t support or is it my programming problem?

VT91:
I am coincidentally using 8 elements that need to report either 0 or 1.

I’m not sure what ‘this’ is that you’re asking about, but if you want to manipulate eight boolean values then the simplest approach would be to represent them as an array of eight booleans, and the most compact representation would be to represent them as a byte; either way is simple in code terms.

I am sorry.
The problem is that this online compiler may not recognize itoa() function.
Or I did something wrong.

Compiling the source code....
$gcc main.c -o demo -lm -pthread -lgmp -lreadline 2>&1
main.c: In function 'main':
main.c:58:5: warning: passing argument 1 of 'atoi' makes pointer from integer without a cast [enabled by default]
atoi (d,buffer,2);
^
In file included from main.c:3:0:
/usr/include/stdlib.h:148:12: note: expected 'const char *' but argument is of type 'unsigned int'
extern int atoi (__const char *__nptr)
^
main.c:58:5: error: too many arguments to function 'atoi'
atoi (d,buffer,2);
^
In file included from main.c:3:0:
/usr/include/stdlib.h:148:12: note: declared here
extern int atoi (__const char *__nptr)

This error has nothing to do with your original question.

atoi() expects a string [a nul terminated array of characters] like "123" as its first argument, or a pointer to a string.

Is it itoa or atoi that you are having problems with? One post shows one, the other the other.

Make your mind up, and then ask the right question.

itoa
that seems not to be as commonly supported as atoi

so it is supposed to cut the number into any integer number system i want and output a string?

itoa is not part of standard C++ , some compilers don't recognize it

edit :
http://www.cplusplus.com/reference/cstdlib/itoa/

char * itoa ( int value, char * str, int base );
Convert integer to string (non-standard function)
......
This function is not defined in ANSI-C and is not part of C++, but is supported by some compilers.

I see.
Well.
I will work around it than.

But..... arduino IDE supports itoa

Arduino IDE supports many non-standard functions.

Use sprintf instead - that IS a standard function, and IS supported by all compilers.

i have nothing to print...
i needed output only to test my algorithm

I said sprintf, npt printf. sprintf does the same thing as printf, but the destination is a string (char array) instead of the screen.

int val = 42;
char out[10];
sprintf(out, "%d", val);
// out[] now contains "42"

See the post by AlphaBeta here: http://forum.arduino.cc/index.php/topic,41625.0.html

struct hours_byte
{
 unsigned int format: 1;     // range: 0-1, 0=24h 1=12h
 unsigned int ampm: 1;       // range: 0-1, 0=AM 1=PM
 unsigned int tenshours: 2;  // range: 0-2 
 unsigned int hours: 4;      // range: 0-15 (guessing it never goes over 9)
};

myStructInstance.myField = var;

var = myStructInstance.myField;

It's good to union it with a byte so you have the entire value for reading / writing in one operation. Also, force packing:

struct hours_byte
{
  union {
    unsigned char value;
    struct {
      unsigned int format: 1;     // range: 0-1, 0=24h 1=12h
      unsigned int ampm: 1;       // range: 0-1, 0=AM 1=PM
      unsigned int tenshours: 2;  // range: 0-2 
      unsigned int hours: 4;      // range: 0-15 (guessing it never goes over 9)
    };
  };
} __attribute__((packed));

struct hours_byte myVal;

myVal.value = 0x89;

// myValue.format == 1
// myValue.ampm == 0
// myValue.tenshours == 0
// myValue.hours == 9