-
Notifications
You must be signed in to change notification settings - Fork 2
/
search.xml
51 lines (51 loc) · 5.94 KB
/
search.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title><![CDATA[配置文件的读写]]></title>
<url>%2F2019%2F5a0fd103.html</url>
<content type="text"><![CDATA[向指定文件中输入key = value,并可以根据key来读取value 配置文件的写入:1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253int WriteCfg(const char *filename,char *key,const char *value) //配置文件写入{ long int FileLength = 0; char *tmp = NULL; char *LineBuf = (char*)malloc(2048); char *FileBuf; int CheckHaveKey = 0; FILE *fp = fopen(filename, "r+"); if (fp == NULL) { fp = fopen(filename, "w+t"); } fseek(fp, 0, SEEK_END); FileLength = ftell(fp); FileBuf = (char*)malloc(FileLength); memset(FileBuf, 0, FileLength); fseek(fp, 0, SEEK_SET); while (!feof(fp)) //查找文件中是否存在key,有的话直接改写value { fgets(LineBuf, 1024, fp); tmp = strstr(LineBuf, key); // 查找该行是否已有key存在 if (tmp != NULL) //该行有目标key,更改该行 { sprintf(LineBuf, "%s = %s\n", key, value); strcat(FileBuf, LineBuf); CheckHaveKey = 1; } if (tmp == NULL) //该行没有目标key,不用改 { strcat(FileBuf, LineBuf); } } if (CheckHaveKey == 1) //如果整个文件中已含有目标key,则更改后重新创建文件写入 { fclose(fp); fp = fopen(filename, "w"); fputs(FileBuf, fp); } if (CheckHaveKey == 0) //如果整个文件中都不含有目标key,则在文件后面追加key { fprintf(fp, "%s = %s\n", key, value); } if (LineBuf != NULL) { free(LineBuf); LineBuf = NULL; } fclose(fp); fp = NULL; return 0;} 获取配置文件的值:123456789101112131415161718192021222324252627282930313233int GetCfg(const char *filename, const char *key,char **value) //根据key获取相应的value到value中{ char *buf = (char*)malloc(sizeof(char) * 100); memset(buf, 0, sizeof(char) * 100); FILE *fp = fopen(filename, "r"); if (fp == NULL) { printf("配置文件不存在\n"); return -1; } while (!feof(fp)) { fgets(buf, sizeof(char) * 100, fp); if ((*value = strstr(buf, key)) == NULL) { continue; } if ((*value = strchr(buf, '=')) != NULL) { break; } } if (*value == NULL) { printf("key不存在\n"); return 1; } *value += 1; clearSpace(*value); //清除字符串中的空格 该函数的实现:https://hhjxx.github.io/2019/a36dd748.html#more fclose(fp); fp = NULL; return 0;}]]></content>
<categories>
<category>C语言</category>
</categories>
</entry>
<entry>
<title><![CDATA[清除字符串中的空格]]></title>
<url>%2F2019%2Fa36dd748.html</url>
<content type="text"><![CDATA[指针作为形参,函数处理后直接改变该指针指向无空格的结果 代码实现如下:1234567891011121314151617181920212223int clearSpace(char *string){ if (string == NULL) return -1; int i, j; int len; char *temp = string ; len = strlen(temp); for (i = 0; i <= len; i++) { if (temp[i] == ' ') { for (j = i; j <= len; j++) //空格后的数据往前移 temp[j] = temp[j + 1]; len--; i--; //移动数据后还要再次检测该位置是否空格(防止多个空格连着,移动后该位置仍然是空格) } else continue; } string = temp; return 0;}]]></content>
<categories>
<category>C语言</category>
</categories>
</entry>
<entry>
<title><![CDATA[计算字符串中的子串数量]]></title>
<url>%2F2019%2F4b90b8af.html</url>
<content type="text"><![CDATA[代码实现如下12345678910111213141516171819int countTarget(char *string,char *target,int *ncount){ int count = 0; if (string == NULL || target == NULL) return -1; while (string != NULL) { string = strstr(string, target); if (string != NULL) { count++; string = string + strlen(target); } else break; } *ncount = count; return 0;}]]></content>
<categories>
<category>C语言</category>
</categories>
</entry>
<entry>
<title><![CDATA[LSB算法BMP图片信息隐藏技术(C语言)]]></title>
<url>%2F2019%2Fd423f60b.html</url>
<content type="text"><![CDATA[LSB算法是将信息的每一位隐藏到BMP格式图片RGB单元的最后一位,由于一位的改变对于颜色影响不大,人的肉眼难以识别,从而达到信息隐藏的效果。具体需要了解BMP文件格式,前54个字节为图片信息,不能修改,所以从第55个字节开始进行隐藏。]]></content>
<categories>
<category>C语言</category>
</categories>
</entry>
<entry>
<title><![CDATA[查找数组中的指定元素]]></title>
<url>%2F2019%2Fb4110e56.html</url>
<content type="text"><![CDATA[在已经排好序的数组中查找指定的数字12345678910111213141516171819int findBin(int a[],int n ,int key){ int low = 0; int high = n - 1; int mid ; while (low <= high) { mid = (low + high) / 2; if (key == a[mid]) { return mid; } if (key < a[mid]) high = mid; if (key > a[mid]) low = mid; } return -1;}]]></content>
<categories>
<category>C语言</category>
</categories>
</entry>
<entry>
<title><![CDATA[数组排序or对数组插入指定数据]]></title>
<url>%2F2019%2F6a20cc18.html</url>
<content type="text"><![CDATA[单个数字按大小插入到已排好序的数组里和插入排序法的关系 单个数字按大小插入到已排好序的数组12345678910111213141516171819#include <stdio.h>void insertArray(int a[],int N,int num) //N是数组下标,num是要插入的数字{ int n = N + 1; int i; for (i = n - 1; i >= 0; i--) { if (num < a[i]) { a[i + 1] = a[i]; } else { a[i + 1] = num; a[i] = num; break; } }} 插入排序法123456void sequnceArray(int a[],int n) //n是数组的下标{ int i; for (i = 1; i < n; i++) insertArray(a, i, a[i]);}]]></content>
<categories>
<category>C语言</category>
</categories>
</entry>
</search>