Skip to content

Instantly share code, notes, and snippets.

View tonyrang's full-sized avatar
:atom:

tony137 tonyrang

:atom:
View GitHub Profile
@tonyrang
tonyrang / sqlite3_test.c
Created June 30, 2020 10:17 — forked from jsok/sqlite3_test.c
sqlite3 C example
#include <stdio.h>
#include <sqlite3.h>
int main(void)
{
sqlite3 *db;
sqlite3_stmt *stmt;
sqlite3_open("expenses.db", &db);
@tonyrang
tonyrang / simple_socket_example.c
Created May 15, 2020 12:57 — forked from browny/simple_socket_example.c
simple socket example in C
/* --- Usage --- */
g++ server.c -o server
g++ client.c -o client
./server
./client 127.0.0.1
/* --- server.c --- */
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <stdio.h>
/* this function is run by the second thread */
void *inc_x(void *x_void_ptr)
{
/* increment x to 100 */
int *x_ptr = (int *)x_void_ptr;
while(++(*x_ptr) < 100);
@tonyrang
tonyrang / semaphore.c
Created May 15, 2020 12:55 — forked from jybaek/semaphore.c
Example for semaphore in C
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h> /* for exit() */
#include <semaphore.h> /* for sem_xxxx() */
sem_t semp;
int val;
static void *wait_fun(void *arg)
{