- 博客(31)
- 资源 (1)
- 收藏
- 关注
原创 简单的,线程创建,线程等待,线程终止。
#include #include #include #include #include char message[]="hello world!";void * thread_function(void *arg){ printf("thread function is running, argument is %s\n",(char *)arg); sleep(
2016-11-30 12:56:42 406
原创 简单的,不同进程间通过消息队列通信
/*send_msg.c*/#include #include #include #include #include #include struct msg{ long msg_types; char msg_buf[512];};int main(){ int qid; int pid; int len; struct ms
2016-11-29 14:32:34 748
原创 简单的,父子进程间通过消息队列通信。
#include #include #include #include #include #include #include #include struct msg_buf { int mtype; char data[255]; }; int main(){ key_t ke
2016-11-28 13:33:53 2025 1
原创 停车场管理系统
设有一个可以停放n辆汽车的狭长停车场,它只有一个大门可以供车辆进出。车辆按到达停车场时间的早晚依次从停车场最里面向大门口处停放(最先到达的第一辆车放在停车场的最里面)。如果停车场已放满n辆车,则后来的车辆只能在停车场大门外的便道上等待,一旦停车场内有车开走,则排以便道上的第一辆车就进入停车场。停车场内如有某辆车要开走,在它之后进入停车场的车都必须先退出停车场为它让路,待其开出停车场后,这些辆再依原
2016-11-27 20:29:53 1779
原创 简单的信号测试程序
#include #include #include #include void myfunc(int sign){ if(sign == SIGINT) { printf("hello world!\n"); } if(sign == SIGQUIT) { printf("exit!\n"); exit(1);
2016-11-26 11:10:36 347
原创 简单的,两个不同进程间的共享内存通信(大小写转换)
/*shmdata.c*/#define TEXT_SZ 2048struct shared_use_st{ int written; char text[TEXT_SZ];};/*shmread.c*/#include #include #include #include #include "shmdata.c"#include int main(){
2016-11-25 10:16:10 891
原创 简单的,父子进程间的共享内存通信
#include #include #include #include #include #include #define BUFFER_SIZE 2048int main(){ pid_t pid; int shmid; char *shm_addr; char flag[]="parent"; char buff[BUFFER_SIZ
2016-11-24 21:26:25 3393
原创 简单的waitpid函数的使用。
#include #include #include #include #include void die(const char *msg){ perror(msg); exit(1);}void child2_do(){ printf("In child2: execute 'date'\n");
2016-11-23 21:33:12 505
原创 简单的实现在有名管道里,进程间的通信(非阻塞)。
/*fifo_write.c*/#include #include #include #include #include #include #include #include #define FIFO_SEVER "/tmp/fifosever"int main(int argc,char *argv[]){ int fd; char w_buf[4096*
2016-11-22 10:16:24 1512
原创 简单的实现,在无名管道里父子进程间的通信(大小写的转换)
#include #include #include #include #include int main(){ int fd[2]; int fd1[2]; pid_t pid; char r_buf[100]; char w_buf[100]; int i; if(pipe(fd) < 0) { perror("pipe error!\n"); ex
2016-11-21 20:10:00 1233
原创 用数据库写简单的通信录
#include #include #include int create_table(sqlite3*db);//表若不存在,则创建int menu(sqlite3*db);//菜单函数int insert_table(sqlite3*db);//插入用户信息int delete_table(sqlite3*db);//删除用户信息int update_table(sqlite3
2016-11-20 20:36:22 662
原创 用链表写简单的通信录
#include#include#includestruct data//创建结点{ char name[10]; char sex[5]; int age; char qq[15]; char phone[15]; struct data*next;};typedef struct data Data;typedef struct data* Link;void
2016-11-19 15:03:05 507
原创 简单的数据库操作(表的创建。记录的插入,删除,显示)
#include #include #include int create_table(sqlite3*db)//创建表,未空的打开{ char *errmsg = NULL; char *sql; sql = "create table if not exists mytable (id integer primary key,name text);"; if(SQLITE
2016-11-18 10:27:44 1012
原创 以行形式写入文件并以行形式读取文件(不带缓存的文件操作且无部分读取)
#include #include #include #include #include #include #define MAX 100int read_line(int fd, char *buf, int count){ int i; char ch; for(i = 0; i < count; i++) { if((read(fd,&ch,1)
2016-11-17 10:08:51 424
原创 用不带缓存的文件操作,打开文件输入字符串并按行读出。
#include #include #include #include #include #include #define MAX 100int read_line(int fd, char *buf, int count){ int i; char ch; for(i = 0; i < count; i++) { if((read(fd,&ch,1)
2016-11-16 08:04:06 312
原创 用带缓存的文件操作实现简单的文件拷贝
#include #include int main(){ FILE *from_fd; FILE *to_fd; char ch; if((from_fd = fopen("from_file","r")) == NULL) { printf("\ncannot open from_file\n"); exit(-1); } if((to_fd = fopen("
2016-11-15 18:10:14 390
原创 用链表写队列
#include#include#includestruct node{ int num; struct node*next;};typedef struct node Node;struct queue_link{ Node*top; Node*buttom;};typedef struct queue_link Queue;void create_queue(Q
2016-11-14 12:48:40 382
原创 用数组写队列
#include#include#include#define MAX 10struct queue_data{ int data[MAX]; int top; int bottom;};typedef struct queue_data Queue;enum return_result {FULL_OK,FULL_NO,EMPTY_OK,EMPTY_NO,PUSH_O
2016-11-13 20:34:13 406
原创 用链表写栈
#include#include#includestruct node{ int num; struct node*next;};typedef struct node Node;struct stacklink{ Node *top;};typedef struct stacklink Stack;void create_stack(Stack **stack)
2016-11-12 19:57:11 291
原创 用数组写栈
#include#include#include#define MAX 10struct stack_data{ int stack[MAX]; int top;};typedef struct stack_data Stack;enum return_result{FULL_OK,FULL_NO,EMPTY_OK,EMPTY_NO,PUSH_OK,PUSH_NO,POP
2016-11-11 10:19:48 431
原创 带表头节点的循环双向链表(头插,尾插,中间插,清除,前向显示,后向显示)
#include#includestruct dblnode{ int num; struct dblnode *prior,*next;};typedef struct dblnode Dblnode;typedef struct dblnode* Dbllink;int is_malloc_ok(Dbllink *newnode){ if((*newnode) ==
2016-11-10 19:22:23 625
原创 带头结点的循环单向链表
#include#includestruct node{ int num; struct node * next;};typedef struct node Node;typedef struct node * Link;void is_malloc_ok(Link new_node){ if(new_node == NULL) { printf("mal
2016-11-09 15:58:47 398
原创 不带头结点的循环单向链表
#include#includestruct node{ int num; struct node * next;};typedef struct node Node;typedef struct node * Link;void create_link(Link * head){ *head = NULL;}void insert_node_head(Link
2016-11-08 10:47:13 3478 1
原创 带头结点的非循环单向链表
#include#includestruct node{ int num; struct node * next;};typedef struct node Node;typedef struct node * Link;void is_malloc_ok(Link new_node){ if(new_node == NULL) { printf("mal
2016-11-07 14:23:52 441
原创 不带表头结点的非循环单向链表
#include#includestruct node{ int num; struct node *next;};typedef struct node Node;typedef struct node * Link;void create_link(Link *head){ *head = NULL;}void insert_node_head(Link *h
2016-11-06 20:57:41 435
原创 编写程序STUDENT *Create(STUDENT studs[],int n)。
STUDENT是一个结构类型,包含姓名、成绩和指针域。studs数组中存储了n个STUDENT记录。create函数的功能是根据studs数组建立一个链表,链表中结点按成绩降序排列,函数返回链表头指针。#include#include#includestruct student//定义结点结构体{ char name[10]; int score; struct student
2016-11-06 18:49:55 1426
原创 建立一个带有头结点的单向链表,并将存储在数组中的字符依次转储到链表的各个结点中
#include#includestruct node//定义结点结构体{ char ch; struct node *next;};typedef struct node Node;//重命名 结点结构体变量typedef struct node* Link;//重命名 指向结点结构体的指针变量int strlen_s(char *s)//求字符串长度{ int i
2016-11-05 21:57:00 1902
原创 编写函数fun(int *a, int n, int *odd, int *even)
功能是:求出数组a[]中所有奇数之和以及所有偶数之和。并利用指针odd返回奇数之和,利用指针even返回偶数之和。 例如:a[]的值依次为:1,9,2,3,11,6;则利用指针odd返回奇数之和24;利用指针even返回偶数之和 8。#include#includevoid fun(int *a, int n, int *odd, int *even){ int i; int
2016-11-04 11:26:38 6119
原创 编写函数int stat(int a[],int n,int c[][2])。
a指向的数组中保存了由n个1位整数组成的数列(n为偶数)。函数从前至后依次将a数组中每两个相邻元素拼成一个不超过2位的整数,从而生成有n/2个元素组成的整数数列;统计该数列中不同整数各自出现的次数,并将统计结果保存到c指向的二维数组中。函数返回不同整数的个数。#include #includeint stat(int a[],int n,int c[][2]){ int i; int
2016-11-03 15:54:32 1594
原创 输入一个字符串,同时输入帧头和帧尾(可以是多个字符),将该字符串中合法的帧识别出来. 提示:帧头和帧尾分别是head和tail 字符串”asdheadhauboisoktail”中headhau
#include#includeint head_flog = 0;//用于标记找到尾的标志int tail_flog = 0;//用于标记找到头的标志char *tail(char *s, char *b)//找到tail地址{ int num = 0;//计数字符长度,和b比较 int len_b; char *temp = b;//用于返回尾地址值的指针 len_b
2016-11-02 15:33:23 1272
原创 输入一个字符串,计算字符串中子串出现的次数
#include#includeint fun(char *a, char *b){ int len_b; int count = 0;//计数子串个数 int num = 0;//计数和b相同字符个数 char *temp = b; len_b = strlen(b);//求b长度 while (*a != '\0') { if (*a == *temp)//计数入
2016-11-01 17:03:05 6299 2
Linux c编程一站式学习(中文版)
2017-11-21
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人