- 博客(30)
- 资源 (1)
- 收藏
- 关注
原创 线程编程练习
编写一个程序,开启3个线程,这3个线程的ID分别为A、B、C,每个线程将自己的ID在屏幕上打印10遍,要求输出结果必须按ABC的顺序显示;如:ABCABC….依次递推。 代码如下/*****************************************************copyright (C), 2014-2015, Lighting Studio.
2016-11-30 22:26:50 241
原创 Linux下的C语言编程——线程编程基本操作
第一步创建线程int pthread_create(pthread_t * restict tidp,const pthread_attr_t * restict,void * (*start_rtn)(void),void * restrict arg)第一个参数: pthread_t * restict tidp 要创建的线程的线程ID指针第二个
2016-11-29 22:20:34 299
原创 Linux下的C语言编程——信号队列
#include #include #include struct msg_buf { int mtype; char data[255]; }; int main(){ key_t key; int msgid; int ret; struct msg_buf m
2016-11-28 22:05:34 313 4
原创 Linux下的C语言编程——共享内存及有名管道的使用
共享内存的使用 char * name = “/dev/shm/myshm”;设置路径 Key = ftok(name,0);shm_id = shmget(key,4096*N,shmflg)创建共享内存P_map = shmat(shm_id,NULL,0);映射共享内存Shmdt(p_map); 解除映射
2016-11-27 20:54:29 733
转载 Linux下的C语言编程——waitpid函数的应用
头文件#include #include 定义函数pid_t waitpid(pid_t pid, int * status,int options)waitpid()会暂时停止目前进程的执行,知道有信号来到或子进程结束。若果在调用wait()时子进程已经结束,则wait()会立即返回子进程结束状态值。子进程的结束状态值会有参数status返回,而子进程也会一块返回。#in
2016-11-26 22:38:14 599
原创 Linux下的C语言编程——sqlite3实现停车场管理系统
通过C语言调用sqlite3API编程实现停车场管理系统#include #include #include #include #include int creat_table(sqlite3 *db){ char *sql; char *errmsg; int i; sql = "create table if not exists carpark (NO inte
2016-11-25 22:04:27 1732
原创 Linux下的C语言编程——进程间通过signal函数通信简单操作
进程间通过signal函数通信简单操作#include #include #include #include void myfunc(int sign){ if(sign == SIGINT) { printf("hello world!\n"); } if(sign == SIGQUIT) {
2016-11-24 22:23:35 1031
原创 Linux下C语言编程——几种可以获取系统时间的函数
#include #include int main(){ time_t rawtime; struct tm * timeinfo; time(&rawtime); timeinfo = localtime(&rawtime); printf("\007 the current data/time is %s\n",asctime(timeinfo));
2016-11-23 22:16:16 823
原创 Linux下的C语言编程——进程间通信——内存共享
进程间通过共享内存来实现通信,完成父进程写入内存,子进程从内存读出并且把大写转换成小写#include #include #include #include #include #include #define BUFFER_SIZE 2048void strupr(char *str){ char *p; p = str; while(*p != '\0')
2016-11-22 22:24:10 1026
原创 Linux下的C语言编程
计算有名管道中读入及写入的字节数#include #include #include #include #include #include #include #define FIFO_SEVER "/tmp/fifosever"int main(int argc,char **argv){ char r_buf[4096*2]; int fd; int
2016-11-21 22:07:38 446
原创 Linux下的C语言编程——进程的简单操作
写两个进程,一个进程往管道里写数据,一个进程从管道里读数据,并且将读出来的数据小写转大写第一个读进程程序#include #include #include #include #include #include #include #define FIFO "/tmp/myfifo"void strupr(char *str){ char *p;
2016-11-20 22:17:56 331
原创 Linux下的C语言编程——错误处理函数
errno查看错误代码errno是调试程序的一个重要方法。当linux C api函数发生异常时,一般会将errno变量(需include errno.h)赋一个整数值,不同的值表示不同的含义,可以通过查看该值推测出错的原因。perrorvoid perror ( const char * str );perror(s) 用来将上一个函数发生错误的原因输出到标准设备
2016-11-19 21:32:57 506
原创 Linux下的C语言编程——求三角形面积
求三角形面积第一点,需要先判断是否是三角形第二点,处理等边三角形第三点,求面积#include #include float solve_len(float a,float b,float c,float d){ float len; float sum; sum = (a - c) * (a - c) + (b - d) * (b - d); len = sq
2016-11-18 21:30:37 1199
原创 Linux下的C语言编程——sqlite3实现通讯录
本来以为可以很快写完的,但是断断续续写了一天。。。。。。这也是自己第一次写这么长的代码,很开心,希望能和大家分享我的代码,亲测运行成功/*****************************************************copyright (C), 2014-2015, Lighting Studio. Co., Ltd. File name:Autho
2016-11-17 19:28:14 1173 3
原创 Linux下的C语言编程——sqlite3的基本操作
第一步: 建立一个数据库,例如建立一个data.db的数据库。在命令行输入sqlite3 data.db。第二步: 有了数据库就要建立一个表。在sqlite3命令行输入create table (字段1,字段2,。。。。。。); 例如建立create table mytable (id integer prim
2016-11-16 20:58:47 686
原创 Linux下的C语言编程——文件存储链表实现的通讯录
研究了好久才把文件加进去,主要是自己太菜了,希望能给大家一点启发!#include #include #include #define N 15struct book// 瀹氫箟缁撴瀯浣?{ char name[N];//濮撳悕 char sex[N];// 鎬у埆 char number[N];//鍙风爜 char QQ[N];// qq char addr[2
2016-11-15 22:26:56 516
原创 Linux下的C语言编程——系统调用read和write函数实现文件拷贝
系统调用read和write函数实现文件拷贝#include #include #include #include #include #include #define SIZE 1024int main(){ int from_fd; int to_fd; int nread; int nwrite; char buff[SIZE]; cha
2016-11-14 22:32:41 6645
原创 Linux下的C语言编程——sqlite3的基本操作
在C语言中实现sqlite3的基本操作#include #include #include int delete(sqlite3 *db){ char *errmsg; char sql[100]; int id; printf("input a id you want to delete!\n"); scanf("%d",&id); sprintf(sql,"dele
2016-11-13 21:29:21 553
原创 Linux下的C语言编程——文件操作
手动创建两个文本文件text1.txt,text2.txt,要求编程创建text3.txt,实现text1.txt和text2.txt文件中除去首行和末尾,其余对应的数据相加,三个文本的内容如下text1.txtbegin10 11 1220 21 2230 31 32end text2.txtbegin15 16 1725 26 2735 36 37end
2016-11-12 22:02:47 516
原创 Linux下的C语言编程——链表实现通讯录
用链表实现简单的通讯录#include #include #include #define N 15struct contact// 瀹氫箟缁撴瀯浣?{ char name[N];//濮撳悕 char sex[N];// 鎬у埆 char number[N];//鍙风爜 char QQ[N];// qq char addr[2*N];// 鍦板潃 struct contac
2016-11-11 20:26:52 599
原创 Linux下的C语言编程——栈操作
栈的基本#include #include #define MAX 10enum return_result{FULL_OK,FULL_NO,EMPTY_OK,EMPTY_NO,PUSH_OK};struct queue_data{ int queue[MAX]; int top; int buttom;};typedef struct queue_data Queue
2016-11-10 22:00:17 258
原创 Linux下的C语言编程——链表实现队列操作
用链表实现队列的操作#include #include struct queue_data{ int num; struct queue_data *next;};typedef struct queue_data Queue;typedef struct queue_data *Link;void creat_queue(Link *head){ *head =
2016-11-09 22:03:32 699
原创 Linux下的C语言编程——用链表实现栈操作
用链表实现栈操作#include #include struct stack{ int num; struct stack *next;};typedef struct stack STACK;typedef struct stack *Link;void creat_stack(Link *head){ *head = (Link)malloc(sizeof(ST
2016-11-08 22:29:00 643
原创 Linux下的C语言编程——队列
队列基本功能的实现#include #include #define MAX 10struct queue_data{ int queue[MAX]; int top; int buttom;};typedef struct queue_data Queue;typedef struct queue_data *Data;void creat_queue(Data
2016-11-07 22:13:08 438
原创 Linux下的C语言编程——双向循环链表的简单实现
下面我先贴上我的代码#include #include struct node{ int num; struct node *next,*prior;};typedef struct node Dbnode;typedef struct node *Dblink;void creat_link(Dblink *head) //创建链表{ *head = (Dblin
2016-11-06 22:02:38 466
原创 Linux下的C语言编程——头插法建立单链表
建立一个带有头结点的单向链表,并将存储在数组中的字符依次转储到链表的各个结点中。#include #include struct node//瀹氫箟涓€涓粨鏋勪綋{ int num; struct node *next;};typedef struct node Node;typedef struct node * Link;int ini
2016-11-05 22:17:32 599
原创 Linux下的C语言编程
编写函数int stat(int a[],int n,int c[][2])。a指向的数组中保存了由n个1位整数组成的数列(n为偶数)。函数从前至后依次将a数组中每两个相邻元素拼成一个不超过2位的整数,从而生成有n/2个元素组成的整数数列;统计该数列中不同整数各自出现的次数,并将统计结果保存到c指向的二维数组中。函数返回不同整数的个数。#include int
2016-11-04 21:29:33 252
原创 Linux下的C语言编程——合法帧
题目:输入一个字符串,同时输入帧头和帧尾(可以是多个字符),将该字符串中合法的帧识别出来.提示:帧头和帧尾分别是head和tail 字符串”asdheadhauboisoktail”中headhauboisoktail是合法帧#include #include void legal_string(char *str,char *str1,char *str2)
2016-11-03 22:48:45 326
原创 Linux下的C语言编程——计算子串的次数
输入一个字符串,计算字符串子串出现的次数。#include #include int count(char *str,char *str1){ int i; int j; int len; i = 0; j = 0; len = 0; while(str[i] != '\0') { if(str[i] != str1[j]) { i++; }
2016-11-02 22:11:30 322
原创 Linux下的C语言编程——计算子串个数
输入一个字符串,计算字符串中子串出现的次数#include #include int count(char *str,char *str1){ int i; int j; int len; i = 0; j = 0; len = 0; while(str[i] != '\0') { if(str[i] != str1[j]) { i++;
2016-11-01 21:29:18 482
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人