Skip to content

Instantly share code, notes, and snippets.

@kylelk
kylelk / primes_and_sums.c
Created September 1, 2013 06:11
primes_and_sums.c
/* This program is solve using for loop. */
#include <stdio.h>
#include <math.h>
int main()
{
int n, count, sum = 0;
printf("Enter an integer: ");
scanf("%d", &n);
for (count = 1; count <= n; ++count) /* for loop terminates if count>n */
@kylelk
kylelk / ghbn.c
Created September 7, 2013 07:12
get host by name
/*
** ghbn.c -- a hostname lookup demo
**
** THIS IS A DEPRECATED METHOD OF GETTING HOST NAMES
** use getaddrinfo() instead.
*/
#include <stdio.h>
#include <errno.h>
#include <netdb.h>
@kylelk
kylelk / showip.c
Created September 7, 2013 07:21
showip.c
/*
** showip.c -- show IP addresses for a host given on the command line
*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
@kylelk
kylelk / hello-world-server.c
Created September 7, 2013 07:25
hello-world-server.c
/* hello-world-server.c - a "hello world" server */
#include <stdio.h> /* Basic I/O routines */
#include <sys/types.h> /* standard system types */
#include <netinet/in.h> /* Internet address structures */
#include <sys/socket.h> /* socket interface functions */
#include <netdb.h> /* host to IP resolution */
#define PORT 5050 /* port of "hello world" server */
#define LINE "hello world" /* what to say to our clients */
/*********************************************************************\
MODULE NAME: b64.c
AUTHOR: Bob Trower 08/04/01
PROJECT: Crypt Data Packaging
COPYRIGHT: Copyright (c) Trantor Standard Systems Inc., 2001
#include <stdio.h>
int main( int argc, char *argv[] )
{
if ( argc != 3 ) /* argc should be 2 for correct execution */
{
/* We print argv[0] assuming it is the program name */
printf( "usage: [%s][N bytes][file name]", argv[0] );
}
else
@kylelk
kylelk / repeat_char.c
Created September 8, 2013 16:22
Function to repeat a character.
#include <stdio.h>
void printchar(char c[128], int n)
{
int i;
for(i=0;i<n;i++)
{
printf("%s", c);
}
printf("\n");
@kylelk
kylelk / bmp-convert.py
Created September 9, 2013 09:31
Convert image to bmp
#/sdcard/Download/M0ori-1.jpg
from pil import Image
im = Image.open("/sdcard/Download/M0ori-1.jpg")
im.save("/sdcard/Download/M0ori-1.bmp", "bmp")
#include <stdio.h>
int main( int argc, char *argv[] )
{
if ( argc != 3 ) /* argc should be 2 for correct execution */
{
/* We print argv[0] assuming it is the program name */
printf( "usage: [%s][N bytes][file name]", argv[0] );
}
else
@kylelk
kylelk / webserver.c
Created September 13, 2013 05:05
web server in c
//
// webserver.c
//
// Simple HTTP server sample for sanos
//
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/stat.h>