Skip to content

Instantly share code, notes, and snippets.

@kelvin-fly
kelvin-fly / 10_num_of1.c
Created October 26, 2012 02:43
get the sum of number's 1
#include <stdio.h>
#include <math.h>
int num_1( int value, int n_bits);
int main()
{
int a, b, c;
scanf("%o",&a);
scanf("%d",&b);
@kelvin-fly
kelvin-fly / 10_factorial.c
Created October 19, 2012 08:09
get the factorial of number,then calculate the end of number 0
#include <stdio.h>
#include <math.h>
int factorial( int );
void coun_0( int );
int main()
{
int n,m;
scanf("%d", &n);
m = factorial(n);
printf("%d\n",m);
@kelvin-fly
kelvin-fly / 10_memmove.c
Created October 19, 2012 05:19
the code is memmove
#include <stdio.h>
#include <string.h>
void *memmovea(char *dest, const char *src, size_t n);
int main()
{
char *dest , *res, *src = "abcdefg";
size_t n = 6;
dest = (char *)malloc(11*sizeof(char));
res = (char *)memmovea(dest,src,n);
@kelvin-fly
kelvin-fly / 10_signed.c
Created October 19, 2012 02:13
check the compiler of cha is signed or not
#include <stdio.h>
int main()
{
char a=-2;
signed char b=-2;
unsigned char c=-2;
printf("a=%d,b=%d,c=%d\n",a,b,c);
return 0;
@kelvin-fly
kelvin-fly / 10_litendian.c
Created October 19, 2012 02:10
check the cpu is little endian or not
#include <stdio.h>
int isLittleEndian();
int main()
{
if(isLittleEndian())
printf(" CPU is LittleEndian");
printf(" CPU is BigEndian");
@kelvin-fly
kelvin-fly / 9_client.c
Created September 11, 2012 01:05
in b/s. the client
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <arpa/inet.h>
#define REMOTE_PORT 1234
@kelvin-fly
kelvin-fly / 9_listener.c
Created September 11, 2012 01:03
in c/s,the listerner.
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/wait.h>
#define MYPORT 5000
@kelvin-fly
kelvin-fly / 9_area.c
Created September 11, 2012 01:02
the area of variable and static
#include <stdio.h>
void foo(void);
int b = 666;
int main()
{
foo();
foo();
printf("what!!\n");
foo();
@kelvin-fly
kelvin-fly / 9_ioctl_ip
Created September 11, 2012 01:00
use ioctl to get ip and mac
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <net/if.h>
#include <arpa/inet.h>
#include <linux/sockios.h>
int main(int argc,char *argv[])
{
@kelvin-fly
kelvin-fly / 9_tree.c
Created September 11, 2012 00:59
the basic of tree
#include <stdio.h>
#define MAXSIZE 100
typedef char DataType;
typedef struct Node
{
DataType data;
struct Node *left;
struct Node *right;
}BTNode, *PBTNode, *BiTreeLink;