随笔分类 - C
摘要:int hS =_timeValue; //_timeValue 单位毫秒 hS = hS%1000; //毫秒秒 int h = sd/(60*60); //时 int m = sd/60 - h*60; //分 int s = sd - h*(60*60) - m*60; //秒
阅读全文
摘要:两个证书 ios_development.cer push.pl2到当前目录:把.cer文件转换成.pem文件:$ openssl x509 -in ios_develoment.cer -inform der-out PushChatCert.pem把私钥.p12文件转换成.pem文件:$ openssl pkcs12 -nocerts -out PushChatKey.pem -in push.p12Enter Import Password:MAC verified OKEnter PEM pass phrase: //两次输入密文,用于验证 serverVerifying –...
阅读全文
摘要:以下信息从网上收集整理----------------------答案一:1.异步传输通常,异步传输是以字符为传输单位,每个字符都要附加 1 位起始位和 1 位停止位,以标记一个字符的开始和结束,并以此实现数据传输同步。所谓异步传输是指字符与字符(一个字符结束到下一个字符开始)之间的时间间隔是可变的,并不需要严格地限制它们的时间关系。起始位对应于二进制值 0,以低电平表示,占用 1 位宽度。停止位对应于二进制值 1,以高电平表示,占用 1~2 位宽度。一个字符占用 5~8位,具体取决于数据所采用的字符集。例如,电报码字符为 5 位、ASCII码字符为 7 位、汉字码则为8 位。此外,还要附加
阅读全文
摘要:#include <stdio.h>int main(){ int a = 0; a = judged("8613775669854"); printf("%d\n",a);}int judged(char *str){ if(strlen(str)!=13 ) //手机号不为13 { return 1; } int i = 0; for(i = 0; i<13; i++) { if(str[i]<'0'|| str[i]>'9') //手机号中有非法字符 { return 2; ...
阅读全文
摘要:#include <stdio.h>#define MAX_NUMBER(a,b) ((a)>(b)) ? (a):(b) //返回较大的一个数。#define MAX(a,b) ((a)/(b)) ? (a):(b) //返回最大的一个数。不用if,等语句int main(){ printf("%d\n",MAX_NUMBER(10,5)); printf("%d\n",MAX(5,6));}
阅读全文
摘要:static int char_to_wchar(const char* orig_str, wchar_t *wtext, int max_length){ int nCoverLen = 0; //add by shenbo setlocale(LC_ALL, "zh_CN.utf8"); nCoverLen = mbstowcs(wtext, orig_str, max_length - 1); if(-1 == nCoverLen){ perror("mbstowcs"); return...
阅读全文
摘要:#include <stdio.h>int is_valid_ip(const char *ip) { int section = 0; //每一节的十进制值 int dot = 0; //几个点分隔符 int last = -1; //每一节中上一个字符 while(*ip) { if(*ip == '.') { dot++; if(dot > 3) { return 0; } ...
阅读全文
摘要:#include <stdio.h>#include <string.h>int main(){ char str[] = "abcde"; char temp[] = ""; int i, j; for(i = 0; i<5; i++) { temp[i] = str [4-i]; } strcpy(str, temp); printf("%s\n",str);}结果: # gcc test_point.c -o test_point # ./test_point str:edcba
阅读全文
摘要:#include <stdio.h>#include <string.h>#define NTP_TIME "/etc/ambaipcam/IPC_Q313/config/NTPaddr.txt"int main(){ FILE *NTPfp ; char szNTP[50][255],ntpjudge[100]; char addr[255],addrbuf[255]; char NTPaddress[255]; //-------------要改的NTP地址 strcpy(NTPadd...
阅读全文
摘要:#include <stdio.h>#include <string.h>FILE *fp = NULL;#define NETWORK_FILE "/etc/network/interfaces"static char* getNetworkInfo(char *maches){ char szBuf[64]; char *szNetwork=NULL; int i = 0; if((fp=fopen(NETWORK_FILE, "r"))==NULL) //判断文件是否为空 { printf( "Can 't
阅读全文
摘要:#include <stdio.h>#define JUDGE_POINT_TWO 1int main(){ #if JUDGE_POINT_TWO char str[] = "qingjoin"; char *ptr = "c program"; char *point; point = str; point[2] = 'a'; point[3] = 'x'; printf("str=%s\n",str); ptr[13] = 'm'; //这个地方是错误的 printf(
阅读全文
摘要:#include <stdio.h>typedef struct shutter //第一个结构体定义{ int min; int max;}shutter_t;typedef struct image_s //第二个结构体定义{ int hue; int sharpness; shutter_t judge; //把第一个结构体里的元素放到第二个结构体里}image_t;int main(){ image_t image; image.hue=5; image.sharpnes...
阅读全文
摘要:void Fifowrite() //Fifo通信{ int real_wnum = 0; int fifo_fd = open(OSD_FIFO,O_WRONLY,0); printf("fifo: %d\n", fifo_fd); if(fifo_fd) { real_wnum = write(fifo_fd,&osd_t,sizeof(textOSD_t)); if(real_wnum...
阅读全文
摘要:#include <stdio.h> //冒泡#define N 10int main(){ int i,j,temp; int a[N]; for(i=0;i<N;i++) { scanf("%d",&a[i]); } for(i=0;i<N-i;i++) { for(j=0;j<N-1-i;j++) { if(a[j]>a[j+1]) { temp=a[j]; a[j]=a[j+1]; ...
阅读全文
摘要:char OsdEndBuf[100][255];char DisplayOsdBuf[100][255];char Txt[50]="Txt", s1_text[50]="s1_text";int Line=-1;int coyOsdbuf() //把文本中的内容复制到数组里{ int i=-1; char *osdfp; char OsdBuf[255]; memset(OsdEndBuf,0,sizeof(OsdEndBuf)); if((osdfp=fo...
阅读全文