代码改变世界

linux 编程笔记1 crusher for linux

2013-11-12 12:35  zoo-code  阅读(189)  评论(0编辑  收藏  举报

1.反显示字符crusher

#include <stdio.h>

int 
main (int argc, char *argv[])
{
	printf("\033[7m more?\033[m \n");
	return 0;
}

  

2.应用反显字符显示当前时间:

 

#include <time.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
	unsigned int now_secs = time(0);
	char *strp = ctime(&now_secs);
	printf("Now time is \033[7m %s \033[m", strp);
	return 0;
}

  

3.读写终端文件 并在另一个窗口写入hello

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>

int main() {

      int fd = open("/dev/pts/1", O_WRONLY);
    if (fd == -1) {
        perror("open pts error\n");
    }
    int res = write(fd, "hello", 5);
    if (5 != res) {
        perror("write error!\n");
    }
    return 0;
}