
C程序
C程序积累
非同_寻常
我们从不生产代码我们只做代码的搬运工
展开
-
c语言--移位运算,统计某个整数2进制含1的个数
#include/** 对数字统计2进制中1的个数* 对一个数字作与运算,将某个位置 设置为0 或者 设置为1*/static int count_one_bit(unsigned int a);void main(){ system("clear"); //清除屏幕多余信息 int a =135; //统计一个整数有多个2进制1 printf("整数%d 含原创 2013-10-12 16:55:27 · 1155 阅读 · 0 评论 -
c语言静态数组创建队列
queue.h#ifndef QUEUE_H#define QUEUE_H#include #define QUEUE_TYPE int /*define the type of the queue*//** create queue * only for dynamic_shuzu_queue */void create_queue(size_t size);/*原创 2013-10-12 12:35:27 · 1524 阅读 · 0 评论 -
c语言静态数组创建栈
static_shuzu_stack.h/** 构造静态数组栈*/#ifndef STATIC_SHUZU_STACK#define STATIC_SHUZU_STACK#define STACK_TYPE int //定义栈数据类型#define STACK_SIZE 9 //定义栈静态数据长度//push 入栈void push(STACK_TYPE value原创 2013-10-12 01:05:12 · 1859 阅读 · 0 评论 -
C语言从一个字符串中,找到最长的回文,并输出
从一个字符串中,找到最长的回文,并输出#include#include/** 从一长串字符串中找到最长的回文长度*/void main(){ char s[50]; int i,l,max=0,k,j,locate; printf("please input the string length <=50!:\n"); scanf("%s",&s); l原创 2013-10-11 01:30:54 · 3985 阅读 · 0 评论 -
C语言数组--快速排序
快速排序 快速排序是对冒泡排序的一种改进,通过一个分界值将数组分成左右两部分,大于等于分界值的元素集中到右边,小于分界值的元素集中到数组左边。对于左右两边的元素又可以取一个分界值继续进行排序,通过递归将左右两侧排好序后,即完成整个数组的排序。#include #include static void QuickSort(int *shuzu,int left,int rig原创 2013-10-05 17:31:18 · 1166 阅读 · 0 评论 -
c语言数组--Shell排序算法
Shell排序算法基本思想:将n个元素的数组分成n/2个数字序列,一次循环使得每个序列排好顺序,然后再变为n/4个序列,再次排序...随着序列减少,最后变成一个,就完成了排序。(排序效率高)#include #include static void ShellSort(int *shuzu,int shuzuLen);void main(){ system("clear"原创 2013-10-05 16:48:39 · 1125 阅读 · 0 评论 -
c语言数组--插入排序
/** 构造一个长度为11的一组数组,使用插入排序法进行排序*/#include #include static void InsertSort(int *shuzu);void main(){ system("clear"); int i=0; int shuzu[11]; srand((unsigned int)time(NULL)); for(i=0;i<原创 2013-10-05 13:06:53 · 1577 阅读 · 0 评论 -
c语言数组--选择排序
/** 使用随机函数生成长度为11的一维数组,使用选择排序算法对其排序*/#include #include static void SelectSort(int *shuzu);void main(){ system("clear"); int i=0; int shuzu[11]; srand((unsigned int)time(NULL)); for(原创 2013-10-04 16:14:41 · 1069 阅读 · 0 评论 -
c语言数组--冒泡排序
#include #include static void BubbleSort(int *shuzu);void main(){ system("clear"); int i=0; int shuzu[11]; srand((unsigned int)time(NULL)); for(i=0;i<=10;i++) { shuzu[i]=rand()%100; }原创 2013-10-04 13:56:47 · 876 阅读 · 0 评论 -
c语言获得网络信息--使用libpcap包
#include #include #include #include #include #include #include int main(int argc,char **argv){ char *dev; char *net; char *mask; int ret; char errbuf[PCAP_ERRBUF_SIZE]; bpf_u_int32 netp原创 2013-10-04 01:05:31 · 1279 阅读 · 0 评论 -
C语言-冒泡排序
#include #include static void BubbleSort(int *shuzu);void main(){ system("clear"); int i=0; int shuzu[11]; srand((unsigned int)time(NULL)); for(i=0;i<=10;i++) { shuzu[i]=rand()%100; }原创 2013-10-03 22:48:24 · 745 阅读 · 0 评论 -
C语言-共用体
/** 共用体:将几个不同类型的变量存放到同一段内存单元。* * 特点:* 1/共用体变量所占的内存长度等于最长的成员长度。* 2/同一个内存可以存放几种不同类型的成员,但每一个瞬间只能存放其中的一种,而不是同时存放几种,结构体变量起作用的就是最后一次存放的成员。* 3/只有定一个了共用体变量才能引用他,而且不能引用共用体变量,只能引用共用体变量的成员。不能对共用原创 2015-07-05 17:06:45 · 727 阅读 · 0 评论 -
C语言—判断IP地址是否合法
判断输入的IP地址是否合法#include unsigned long ip;int judge(int ,int ,int ,int);void main(){ char *ipstr[50]; int a,b,c,d; printf("please input a ip\n"); scanf("%s",ipstr); sscanf(ipstr,"%d.%d.%d.原创 2015-07-11 21:56:51 · 7211 阅读 · 0 评论 -
C语言-输出彩色字体
/*用 vt码 例:printf("\033[40;31m你要改变颜色的内容\033[0m"); 背景色为黑色,字体颜色位红色只想要背景色printf("\033[40m你要改变颜色的内容\033[0m");只想要自提颜色同上 改一下数字就行了 背景色40:黑41:深红42:绿43:黄色44:蓝色45:紫色46:深绿47:白色字体颜色:30-----------39原创 2015-07-05 19:22:37 · 16434 阅读 · 4 评论 -
c语言--静态数组创建树
tree.h#ifndef TREE_H#define TREE_H/** 二叉搜索树程序接口*/#define TREE_TYPE int /* define the value type of the tree*//** insert* add value to tree ,the value must not exist in the tree*/void原创 2013-11-03 23:50:30 · 1329 阅读 · 0 评论 -
C语言-统计一行句子中单词的个数
输入一行句子,统计其中单词的个数/** 输入一句话,统计其中的单词个数,单词之前使用空格隔开*/#include void main(){ char sentence[1024]={'\0'}; int isSpace=1; int i=0; int wordCount=0; printf("please input a sentence (length <原创 2015-06-22 22:17:14 · 7215 阅读 · 1 评论 -
C语言-求数字阶乘(递归函数)
/** C语言 求数字的阶乘*/#include <stdio.h>#include <stdlib.h>long jiecheng(int n);void main(){ int n=0; printf("input a integer number!\n"); scanf("%d",&n); if(n<0) { printf("原创 2015-06-23 22:28:55 · 2006 阅读 · 0 评论 -
c语言mysql查询数据库
#include#include#includeint main(){ MYSQL mysql; MYSQL_RES *res=NULL; MYSQL_ROW row; MYSQL_FIELD *fields; //保存字段名字信息 unsigned int num_fields; unsigned int i原创 2013-10-12 17:13:48 · 1249 阅读 · 1 评论 -
c语言对一组数据随机排序
/*** 程序功能:对指定的数组,进行随机排序,交换数组中的数据位置*/#include #include void swap(int *tempa,int *tempb);void main(){ int a[10]={0,1,2,3,4,5,6,7,8,9}; int i; int j=0; for(i=0;i<10;i++) { j=(int)原创 2013-10-12 16:39:41 · 10120 阅读 · 3 评论 -
给定一个数字,求比它大的最小的非重复数字
题目:整数中相邻的数字重复即为重复数字 如‘1101’,其他则为正常数字如‘1203’。 给定一个数字,求比它大的最小的非重复数字原创 2013-10-04 00:54:00 · 1365 阅读 · 0 评论 -
c语言字符数组大小写转换
2014 全志科技校园招聘笔试题-------编程:题目:给定字符串''just do it !'',将其转化为大写"JUST DO IT!"/*** 给定一组字符串"just do it!",将其变成全部大写"JUST DO IT!"* 方法一:判断字符串范围,对 >=‘a’ && <='z' 的字符串进行转换,即 += 'A'-'a'*/#include #in原创 2013-10-13 20:37:53 · 12132 阅读 · 0 评论 -
snort_rules/doc/signatures 规则解析放入MySql数据中
程序功能描述: 对snort_rules/doc/signatures 下的所有规则文件(如图1),进行单个规则文件读取(每个文件如图2所示),提取对规则的描述信息,然后对应PID-SID为关键字存储到MySql数据库当中(如图3所示) 图1——signatures文件夹,文件目录截图 图2——单个规则文件打开截图原创 2013-10-17 12:36:30 · 1602 阅读 · 0 评论 -
输入一长串字符串,并对指定的开始位置和结束位置内的字符串反转
功能描述: 输入一长串字符串,并对指定的开始位置和结束位置内的字符串反转#include"stdio.h"#include"stdlib.h"#define N 100int main(){ system("clear");//清除屏幕(linux下使用) char c[N],temp; int i=0; int j=0; int start=0;原创 2013-10-17 13:00:38 · 2091 阅读 · 0 评论 -
c语言mysql连接
工程项目中经常要与mysql交互,留下自己写的接口,方便下次使用,mysql.h#ifndef MYSQL_H#define MYSQL_H#include "/usr/include/mysql/mysql.h"/** 定义连接信息*/#define MYSQL_CONNECT_IP "XXX.XXX.XXX.XXX"#define MYSQL_US原创 2013-10-12 17:07:39 · 783 阅读 · 0 评论 -
c语言获得设备端口列表--使用libpcap包
/*device_list.c*/#include #include #include #include pcap_t *fp[10];void main(){ /*获取单个设备信息,默认第一个设备名称*/ /* char error_content[PCAP_ERRBUF_SIZE]; char *net_interface; u_int32_t net_ip;原创 2013-11-26 13:09:18 · 1768 阅读 · 0 评论 -
c语言指定网口转发数据包---使用libpcap包
sendPkt.c#include #include int main(int argc, char **argv){ system("clear"); pcap_t *fp; char errbuf[PCAP_ERRBUF_SIZE]; pcap_t *descr= pcap_open_offline("/home/IPS/test.pcap",errbuf); co原创 2013-11-26 13:14:31 · 4600 阅读 · 0 评论 -
c语言指定网口捕获数据包--使用libpcap包
/*Listing 2. Simple snifferTo compile: gcc simplesniffer.c -o simplesinffer -lpcap*/#include #include int main(int argc, char **argv){ system("clear"); pcap_t *fp; char errbuf[PCAP转载 2013-11-26 13:19:15 · 3503 阅读 · 1 评论 -
c语言时间函数
C语言time.h从头学本文从介绍基础概念入手,探讨了在C/C++中对日期和时间操作所用到的数据结构和函数,并对计时、时间的获取、时间的计算和显示格式等方面进行了阐述。本文还通过大量的实例向你展示了time.h头文件中声明的各种函数和数据结构的详细使用方法。 关键字:UTC(世界标准时间),Calendar Time(日历时间),epoch(时间点),clock tick(时钟计时单元转载 2013-12-03 19:09:07 · 1019 阅读 · 0 评论 -
c语言网络编程-设置非阻塞方式
#include #include #include #include #include #include #include #include #include #include #define MAXBUF 10/************关于本文档*********************************************filename: simple-转载 2013-12-04 10:39:23 · 3657 阅读 · 0 评论 -
C语言-判断闰年
C语言判断闰年runnian.c/* 判定2000-2500年中的每一年是否是闰年*/#include void main(){ int year=2000; for(year=2000;year<2500;year++) { if(0 == year%4 && 0 != year%100) { printf("%d ",year); }原创 2015-06-16 22:40:45 · 1047 阅读 · 0 评论 -
C语言-解析命令行参数
#include #include/*函数说明 : int getopt(int argc,char * const argv[ ],const char * optstring);) 用来分析命令行参数。参数argc和argv分别代表参数个数和内容,跟main()函数的命令行参数是一样的。 参数 optstring为选项字符串, 告知 getopt()可以处理哪个选项以及哪个选项需原创 2015-07-05 22:57:05 · 3507 阅读 · 0 评论