Skip to content

Instantly share code, notes, and snippets.

@khajavi
khajavi / Makefile
Created June 1, 2013 11:08
Example of adding new attribute to xml nodes by using libxml2 library.
CC = gcc
CLIBS = `pkg-config libxml-2.0 --cflags --libs`
add_attr: add_attribute_example.c
$(CC) add_attribute_example.c -o add_attribute_example.bin $(CLIBS)
clean:
rm -f *.o *.bin
@khajavi
khajavi / Makefile
Created June 1, 2013 10:57
Example of adding new keyword tag to specific xml node by libxml2
CC = gcc
CLIBS = `pkg-config libxml-2.0 --cflags --libs`
add_keyword: add_keyword_example.c
$(CC) add_keyword_example.c -o add_keyword_example.bin $(CLIBS)
clean:
rm -f *.o *.bin
@khajavi
khajavi / Makefile
Created June 1, 2013 09:49
Example of parsing xml by libxml2
CC = gcc
CLIBS = `pkg-config libxml-2.0 --cflags --libs`
parse_xml: parse_xml.c
$(CC) -g -O0 parse_xml.c -o parse_xml.bin $(CLIBS)
clean:
rm -f *.o *.bin
@khajavi
khajavi / Makefile
Last active December 17, 2015 23:29
Example of parsing xml by evaluating xpath expression and libxml2
CC = gcc
CLIBS = `pkg-config libxml-2.0 --cflags --libs`
xpath: xpath_example.c
$(CC) xpath_example.c -o xpath_example.bin $(CLIBS)
clean:
rm -f *.o *.bin
@khajavi
khajavi / convert_float_to_ieee754.c
Created May 29, 2013 10:42
example of conveting float numbers to ieee 754 in single and double precison format.
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
/*
* See also : http://class.ece.iastate.edu/arun/CprE281_F05/ieee754/ie5.html
*/
union FloatingPointSinglePrecisionIEEE754 {
struct {
@khajavi
khajavi / floating_point_ieee.c
Created May 29, 2013 04:25
Converting floating-point number to IEEE754 representation by using union and struct in c.
#include <stdio.h>
/*
* See also : http://class.ece.iastate.edu/arun/CprE281_F05/ieee754/ie5.html
*/
union FloatingPointIEEE754 {
struct {
unsigned int mantissa : 23;
unsigned int exponent : 8;
unsigned int sign : 1;
@khajavi
khajavi / bitfield.c
Created May 29, 2013 03:15
example of bitfield in c programming.
#include <stdio.h>
struct Bitfield {
int a:4;
unsigned int b:4;
} bit;
struct Boolean {
unsigned int a:1;
} boolean;
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
int main() {
union
{
uint8_t c[4];
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
struct A {
bool a:1;
bool b:1;
bool c:1;
bool d:1;
};
@khajavi
khajavi / simple_cairo.c
Created May 26, 2013 21:05
Simple gtk base caro example
#include <gtk/gtk.h>
#include <cairo.h>
static gboolean
on_draw_event( GtkWidget* widget,
cairo_t *cr,
gpointer user_data ) {
cairo_set_source_rgb( cr, 0.3, 0.5, 0.8 );
cairo_rectangle( cr, 100, 100, 50, 50 );