C/C++
文章平均质量分 79
keepcode
这个作者很懒,什么都没留下…
展开
-
C语言拼接字符串和整型
用sprintf合拼char name[10] = "hello"; int age = 123;char buffer[80];sprintf(buffer, "%s%d xx", name, age);printf("%s",buffer);buffer就是合并后的字符串。相关函数:sscanf(),相当于拆分。#include int main(void){原创 2015-11-10 14:22:23 · 10013 阅读 · 0 评论 -
C++入门基础语法
#include using namespace std;//使用std块,这样就不需要std::cout这样写了。class A{public: A(int a,int b):x1(a),x2(b) { cout <<"class A a&b: " << a <<" & "<< b <<endl; cout <<"class A x1&x2: " << x1 <<" & "<原创 2015-11-08 20:25:54 · 311 阅读 · 0 评论 -
linuxC语言socket广播通信
广播: 发送给所有主机// enable BROADCASTint on = 1;setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST,&on, sizeof(on));需要解析到传输层才能决定是否需要处理SOCKET属性:必须在socket之后 ,bind(如果有的话)之前设置int on = 1;setsockopt(sock原创 2015-09-27 14:28:46 · 1797 阅读 · 0 评论 -
C语言的中断信号
信号:中断信号 ----- 软中断(SIGSEGV)、硬中断(SIGINT ctrl+c)gec@ubuntu:/$ kill -l1) SIGHUP 2) SIGINT 3) SIGQUIT4) SIGILL 5) SIGTRAP6) SIGABRT 7) SIGBUS 8) SIGFPE9) SIGKILL 10) SIGUSR111) SIGSEGV原创 2015-09-12 22:01:11 · 4841 阅读 · 0 评论 -
C语言简单进程
进程:进程是正在运行的程序的实例进程是一个具有独立功能的程序关于某个数据集合的一次运行活动是系统进行(资源分配和调度)的基本单位,是操作系统结构的基础是一个动态的概念,是一个活动的实体init是个有超级权限的用户进程执行态(Running):包括运行和就绪 睡眠(sleeping):(S)浅睡眠 interruptable 进程在等待一个事件的发生或者某种原创 2015-09-12 22:08:53 · 772 阅读 · 0 评论 -
lcd图片缩小
void img_small3(const unsigned char *p){ int y, x,color; //压缩1/4。每4个点失去1个,一行也就失去200。 for(y = 0;y < 360 ;y++) { if(!(y%3))p+=(800*3);//判断屏幕的行,然后跳过颜色的那一行,指向下一行,注意!(y%3)要加括号,要不然先执行!y for(x = 0;x <原创 2015-08-22 14:53:09 · 632 阅读 · 0 评论 -
飞秋基本udp通信
简单实例:#include #include #include #include #include #include #include #include #include int main(int argc, char const *argv[]){ struct sockaddr_in m_addr,u_addr; int len; int sockfd; char原创 2015-09-27 15:17:30 · 6305 阅读 · 0 评论 -
linux下C语言UDP通信
UDP:无连接不可靠, 但是在稳定的网络中效率高socket( AF_INET, SOCK_DGRAM ,0) ;struct sockaddr_in;bind( ); // 为了确定目标sendto (int socket, const void *message, size_t length, int flags, const原创 2015-09-27 14:24:28 · 851 阅读 · 0 评论 -
C语言函数-指针
函数.指针函数指针是指向函数的指针变量,即本质是一个指针变量。 int (*f) (int x); /* 声明一个函数指针 */f=func; /* 将func函数的首地址赋给指针f */实例:#include int (*show)(const char *,...);int main(int argc, char const *argv[]){ show原创 2015-08-07 23:45:08 · 371 阅读 · 0 评论 -
C语言去除字符串空格
/*指针去除字符串空格*/#include #include int main(){ char str[]="i apple tr ee"; char *q,*p; p=q=str; while(*p!='\0') { if(*p!=' '){ *q++=*p++; } else{ p++; } } *q='\0'; printf("%原创 2015-08-05 00:01:52 · 1596 阅读 · 0 评论 -
linux进程通信--共享内存
共享内存:shm共享内存是在两个正在运行的进程之间共享和传递数据的一种非常有效的方式;并未提供同步机制申请shmid = shmget(key_t , sizeof() , 0666|IPC_CREAT)-- 得到int shmid 销毁shmctl(shmid, IPC_RMID, 0 );连接映射void * shm = shmat (shm原创 2015-09-19 22:37:13 · 316 阅读 · 0 评论 -
linux进程通信--消息队列
消息队列:针对不同的对象发送消息 创建并打开:int msgid = msgget(key_t, 0666|IPC_CREAT); 销毁:msgctl(msgid, IPC_RMID, 0 );发送消息:msgsnd(msgid, struct msg指针 , 有效数据size ,msgflg );struct msg {long int ms原创 2015-09-19 22:44:21 · 333 阅读 · 0 评论 -
C语言进程间通信
进程间通信:1: 资源共享 --- 2: 数据传输 --- 发送接受信息3: 通知事件 --- 信号4: 进程控制 --- 控制进程状态转换比较古老:无名管道(PIPE)有名管道(FIFO ,named pipe)信号(signal)SYSTEM V IPC信号量(Sem)共享内存(shm)消息队列(Msg)BSD 套接字(Soc原创 2015-09-12 21:54:55 · 7922 阅读 · 0 评论 -
Qt的socket通信
service端mainwindow.cpp#include "mainwindow.h"#include "ui_mainwindow.h"#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupU原创 2015-11-22 11:51:00 · 477 阅读 · 0 评论 -
C语言学习web服务器小实例
service.c#include #include #include #include #include #include #include #include #include #include #include #include #include #define SERVER_STRING "Server: xx\r\n"void *accept_reque原创 2015-11-22 15:07:27 · 576 阅读 · 0 评论 -
C语言数据结构
#include #include struct abc{ int a; char b; struct abc *next;};void fun1(struct abc *myabc){ printf("%d\n",myabc->a );}void fun2(struct abc myabc){ printf("%d\n",myabc.a );}struct abc原创 2015-10-31 21:05:28 · 370 阅读 · 0 评论 -
linux下c语言tcp通信
TCP/IP 协议组:应用层 (FTP / SMTP / HTTP)传输层 (TCP / UDP)网络层 (IP ICMP IGMP)物理层(网络接口层、链路层) (以太网、令牌环网、FDDI)实例:服务端#include #include #include #include #include #include #include #include原创 2015-09-26 12:38:49 · 638 阅读 · 0 评论 -
C语言信号集处理函数
信号内核和用户空间通信,软件上对中断机制的模拟,异步通信信号是内核产生信号的发送(用户空间用kill( 信号, pid) 、 raise(信号))捕获 ( SIG_IGN, 自定义的信号处理函数 ,SIG_DFL)一些常用信号SIGQUIT CTRL+\SIGINT CTRL+CSIGSTOP 暂停 --- 不能更改信号处理方式SIGKILL 终止 ---原创 2015-09-19 23:02:59 · 1540 阅读 · 0 评论 -
linux守护进程
进程中的守护进程:Daemon 什么是守护进程:提供后台服务,系统开启到关闭都存在,1:独立于终端,有专职任务终端:TTY项, 独立于终端是?,和终端相关则有具体名称如: pid,ppid, pgrp,tty, comm2306 2299 2306 pts/0bash如何独立?忽略SIGHUP2:父进程是init fork后让原创 2015-09-19 23:07:12 · 285 阅读 · 0 评论 -
linux进程通信--信号量
信号量 --- 进程间或线程间同步讲的是system V里面的信号量二值信号量 只有0和1两个值1 0计数信号量 有n个值4 3 2 1 0 图书馆借书~借出书 : n-1 ------ 进程申请信号量 P操作归还书: n+1 ------ 进程释放信号量 V操作p 操作v 操作等0操作 --- 书都被借完了s原创 2015-09-19 22:54:46 · 398 阅读 · 0 评论 -
linux线程通信
线程进程是系统分配资源的基本单位线程是系统调度的基本单位,共享进程的全部资源一个进程可以有一个或者多个线程,线程一定对应一个进程线程的属性之一:detach mode 默认是非分离状态,也就是需要主线程去回收资源的,用的是join。 就绪---> 运行态 ---> 阻塞 ---> 就绪创建 : 进程fork线程:pthread_crea原创 2015-09-20 00:41:48 · 402 阅读 · 0 评论 -
linux创建线程
线程:进程:资源分配的基本单位线程:系统调度的基本单位 线程创建: pthread_create (&tid 返回子线程ID, 属性,子线程函数入口(函数指针),函数传入参数) sqrt :-lm --> - link libm.a pthread:-lpthread -> -link libpthread.a线程创建时候要注意属性:优先级原创 2015-09-19 23:27:59 · 2377 阅读 · 0 评论 -
C语言按键控制led灯和蜂鸣器
循环流水灯和蜂鸣器,按键结束#define rGPJ2CON (*(volatile unsigned long *)0xe0200280)#define rGPJ2DAT (*(volatile unsigned long *)0xe0200284)#define rGPD0CON (*(volatile unsigned long *)0xe02000a0)#define rGPD0D原创 2015-08-16 10:37:17 · 7868 阅读 · 0 评论 -
arm的lcd显示字体
#include "stdio.h"#include "s5pv210.h"unsigned int *fbuf = (unsigned int *)0x42000000;char ywy[5][32]={{0x20,0x02,0x70,0x0A,0x1E,0x12,0x10,0x12,0x10,0x02,0xFF,0x7F,0x10,0x02,0x10,0x22,0x50,0x22原创 2015-08-17 23:09:13 · 1247 阅读 · 0 评论 -
C语言结构体
#include int main(int argc,char **argv){ /*1.声明名称myabc新的数据类型*/ struct myabc { char a; short b; int c; }; // 2.定义结构体变量abc struct myabc abc ; // 3.初始化结构体变量 abc.a = 77; abc.b = 88; ab原创 2015-07-26 15:04:00 · 356 阅读 · 0 评论 -
内存空间的一般性区域分布图
示例代码:#include #include int a=1;static int b;static int c=4;int d;int main(int argc, char const *argv[]){ int e=1; int f; static int g=3; printf("a=%p\n", &a); printf("b=%p\n", &b); prin原创 2015-07-28 23:34:07 · 650 阅读 · 0 评论 -
数组-指针
示例代码:#include int main(int argc, char const *argv[]){ int c[4]={1,2,3,4};int *a[4]; //指针数组int (*b)[4]; //数组指针b=&c;int i;//将数组c中元素赋给数组afor( i=0;i<4;i++){ a[i]=&c[i];} printf("%d\n",原创 2015-07-28 23:56:49 · 320 阅读 · 0 评论 -
结构体运用
函数传结构体值#include struct myabc{ int a; int b; int c;};void fun(struct myabc *pabc){ printf("%d\n", pabc->a); printf("%d\n",pabc);}int main(int argc, c原创 2015-07-28 23:54:07 · 489 阅读 · 0 评论 -
C语言数组练习相关
1 类型决定内存空间的大小。大小: 类型*m 2 数组名是一个依赖于成员个数的地址3 m不是限定符,不是一个强制性的限定符,只是一个说明符#include int main(){ int a[10]; char b[10]; int *p1=a; char *p2=b; printf("%d,%d\n",sizeof(a),p1); printf("%d,%d\n",s原创 2015-08-07 23:29:13 · 272 阅读 · 0 评论 -
C语言字符串定义
字符串定义char str1[10] = {'h','e','l','l','o','\0'};char str2[10] = {"hello"};char str3[10] = "hello";char str4[] = "hello";二维数组字符定义const char str1[2][8] = {"hello","world"};const char *str2[2] = {原创 2015-08-07 23:32:59 · 660 阅读 · 0 评论 -
C语言多级指针
/*多级指针*/#include int main(int argc, char const *argv[]){ int a=1; int *p=&a; int **p2=&p;//2级指针指向指针变量p的地址。 //char **p2=(char **)&p; printf("%d\n",*p ); printf("%d\n",*p2 ); printf("%d\n",**p原创 2015-08-07 23:20:34 · 337 阅读 · 0 评论 -
C语言函数相关
/*函数传参*/#include int a=1,b=2;int *p;//传p地址函数void fun(int **t){ *t=&b;}/*//传a地址函数void fun(int *t){ *t=b;}*/int main(int argc, char const *argv[]){ p=&a; printf("%d\n",*p); fun(&p);//传p原创 2015-08-07 23:18:40 · 358 阅读 · 0 评论 -
静态配置ip
# vim /etc/network/interfacesauto eth0iface eth0 inet staticaddress 192.168.1.5netmask 255.255.255.0gateway 192.168.1.1# vi /etc/resolvconf/resolv.conf.d/basenameserver 192.168.1.1# vi /etc/原创 2015-08-09 01:27:55 · 274 阅读 · 0 评论 -
指针将整型组的值逆序存放
方法一:#include void inverted(int *p,int n){ int *a,*b,t,m=(n-1)/2; a=p+n-1;//a存放末尾地址 b=p+m;//b存放中间位置 for (;p<b; p++,a--) { t=*p; *p=*a; *a=t; //*p是首位置,然后与末尾进行交换。 }}int main(int argc,原创 2015-07-28 23:42:34 · 1116 阅读 · 0 评论 -
arm开发板触摸
主程序#include "s5pv210.h"#include "stdio.h"#include "usdf.h"//如果在本目录下没找到此文件,就会去找框架里的include目录void EXTI4_IRQHandler(void);void Eint14_init(void);void I2c_Init();void I2c_PortInit();void FT5x06_原创 2015-08-22 15:06:11 · 442 阅读 · 0 评论 -
arm的lcd屏保动圆
#include "stdio.h"#include "s5pv210.h"unsigned int *fbuf = (unsigned int *)0x42000000;void lcd_PortInit(){ rGPF0CON = 0x22222222; rGPF1CON = 0x22222222; rGPF2CON = 0x22222222; rGPF3CON = 0x22原创 2015-08-17 22:27:41 · 934 阅读 · 1 评论 -
arm中断控制led
board/keyled_intr.c#include "stdio.h"#include "s5pv210.h"void Eint16_isr(){ if(rEXT_INT_2_PEND==0x1) { printf("key2 put down\n"); rEXT_INT_2_PEND |=(0x1<<0); //清除中断标志位 rVIC0ADDRESS = 0x0原创 2015-08-16 11:24:05 · 3069 阅读 · 0 评论 -
arm定时器4
board/timer4led.c#include "stdio.h"#include "s5pv210.h"void t4_init(){ //TCFG0[15:8] = 99 //设置t4预分频值 rTCFG0 &=~(0xff<<8); rTCFG0 |=(0x63<<8); //TCFG1[19:16] = 0100 //选择PWM定时器的选通输入 rTCFG1原创 2015-08-16 11:38:10 · 684 阅读 · 0 评论 -
arm定时器0
board/timer0_beep.c#include "stdio.h"#include "s5pv210.h"#define rTCNTB0 (*(volatile unsigned long *) 0xE250000C)#define rTCMPB0 (*(volatile unsigned long *) 0xE2500010)void t0_PortInit(){ /原创 2015-08-16 11:32:24 · 595 阅读 · 0 评论 -
arm的lcd基础显示
进行逐行扫描RGB的数值,显现出来。图片需要通过image2lcd工具,转为字符数组那样的格式。它每3个值为RGB颜色值,然后放入include文件夹,然后导入即可。board/fimd_lcd.c#include "stdio.h"#include "s5pv210.h"#include "img1.h"unsigned int *fbuf = (unsigned int *原创 2015-08-16 14:32:06 · 871 阅读 · 0 评论