Linux C
FreeBeer2015
一步一个脚印踏踏实实
展开
-
Fedora 17安装MySql服务
第一步: yum install mysql yum install mysql-server第二步: systemctl start mysqld.service第三步: mysqladmin -u root password [your password here]第四步: mysql -h localhost -u root -p第五步原创 2013-03-18 10:40:35 · 846 阅读 · 1 评论 -
单链表操作
//head.h#include #include #include typedef struct Node{ int data;//数据域 struct Node *next;//结点域}Node;Node *create(int count);//创建新结点int length(Node *head);//返回单链表的长度void print(Node *原创 2013-06-12 13:34:27 · 668 阅读 · 0 评论 -
使用fcntl锁定文件,并且测试
//lock1.c/*程序首先创建一个文件,并且以可读的方式打开,然后在文件中添加一些内容,接着在文件中设置两个区域,第一个区域为10-30字节,使用共享锁;第二个区域为40-50字节,使用独占锁,然后程序调用fcntl函数来锁定这两个区域,并在关闭文件和退出程序前等待一分钟*/#include #include #include #include const c原创 2013-05-28 20:23:46 · 1421 阅读 · 0 评论 -
字符驱动之四阻塞IO(等待队列)
我们经常看到 read 的时候没有数据可读,而有时却是 write 的时候缓冲区已 满写不进去。而应用程序不关心这个,只关心我要的数据何时能读取出来,或者我 写的数据何时才能写进去。因此这样应该要阻塞进程,直到有数据可读或者有内存 可写。那我们就来看看几个概念和问题: 1)何为进程睡眠? 2)是否什转载 2013-05-13 21:17:56 · 621 阅读 · 0 评论 -
GTK编程入门
#include int main(int argc,char *argv[]){ GtkWidget *window;//定义一个指向窗口的指针 char title[] = "Hello World";//设置窗体的标题 gtk_set_locale(); gtk_init(&argc,&argv);//建立窗口 window原创 2013-05-27 20:43:44 · 1288 阅读 · 1 评论 -
获取域名的IP地址
#include #include #include #include #include #include int main(){ struct hostent *host; char hostname1[] = "www.baidu.com"; char hostname2[] = "www.google.com.cn"; struct in_ad原创 2013-05-26 10:29:34 · 2052 阅读 · 0 评论 -
创建临时唯一的文件
#include #include int main( ){ int fd; char template[ ]="template-XXXXXX"; fd=mkstemp(template); printf("template = %s\n",template); close(fd); return 0;}原创 2013-05-24 20:54:49 · 785 阅读 · 0 评论 -
另类HelloWorld
#include #define __(a) goto a; #define ___(a) putchar(a); #define _(a,b) ___(a) __(b); main() { _:__(t)a:_('r',g)b:_('$',p) c:_('l',f)d:_(' ',s)e:_('a',s) f:_('o',q)g:_原创 2013-04-11 16:48:28 · 5939 阅读 · 0 评论 -
const用于指针
1)const int *pp是一个指向整型常量的指针,可以修改指针的值,但不能修改指针所指向的值#include int main(){ int b = 5; int c = 3; const int *p = &b; printf("*p is %d\n",*p); *p = 6;//错误,向只读位置 *p赋值 p = &c;//原创 2013-03-24 12:30:53 · 1102 阅读 · 0 评论 -
输入密码时显示*并且退格可以删除密码
#include#include#include#define PS "love"int pass(void){ int x,n=1; char passwords[20]=PS; for(;;n++) { if(n<=3) { char ch,passwords0[20];原创 2013-04-01 18:34:46 · 1943 阅读 · 1 评论 -
双向冒泡排序
/* ============================================================================ Name : Bubble.c Author : AnPan Version : Copyright : Your copyright notice Description : Hello W原创 2013-03-16 20:02:07 · 744 阅读 · 0 评论 -
合并两个已经按递增排序的文件
合并两个已经按递增排序的文件#include #include #define SIZE 1024int main(int argc,char **argv){ if(argc != 4) { printf("Please try Use --help\n"); return -1; } FILE *fp1,*fp原创 2013-03-16 16:54:13 · 1378 阅读 · 0 评论 -
队列操作
//head.h#ifndef HEAD_H#define HEAD_H#include typedef struct Node{ int data; struct Node *next;}Node;typedef struct Queue{ Node *front; Node *rear;}Queue;Queue *CreateQueue原创 2013-06-13 20:26:03 · 770 阅读 · 0 评论