字符串处理
来源:互联网 发布:淘宝兼职软件 编辑:程序博客网 时间:2024/06/05 20:01
#include <stdio.h>
#include <string.h>
#define KEYWORD "filter"
#define FILTER_FILE "/etc/key_rules.conf"
char *clearup_string1(char *buf)
{
int len;
char ch;
char *ptr;
if (NULL == buf)
return NULL;
/* skip space and tab */
while(*buf)
{
if (*buf == ' ' || *buf == '\t')
buf++;
else
break;
}
if (buf)
ptr = buf;
else
return NULL;
/* skip space and tab, return and new line character */
len = strlen(buf);
while(len){
ch = buf[len-1];
if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n'){
buf[len-1] = '\0';
len--;
}
else{
break;
}
}
return ptr;
}
char *clearup_string2(char *buf)
{
int len;
char ch;
char *ptr;
if (NULL == buf)
return NULL;
/* skip space and tab */
while(*buf)
{
if (*buf == ' ' || *buf == '\t' || *buf == '=' || *buf == '\"')
buf++;
else
break;
}
if (buf)
ptr = buf;
else
return NULL;
/* skip space and tab, return and new line character */
len = strlen(buf);
while(len){
ch = buf[len-1];
if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n' || ch == '=' || ch == '\"'){
buf[len-1] = '\0';
len--;
}
else{
break;
}
}
return ptr;
}
int main()
{
FILE *fp;
char *ptr;
char buf[1024];
fp = fopen(FILTER_FILE, "r");
if (NULL == fp)
{
fprintf(stderr, "fopen fail.\n");
return -1;
}
/* reverse file line by line */
while(fgets(buf, sizeof(buf), fp))
{
if ( NULL != (ptr = clearup_string1(buf)))
{
if (*ptr == '#') /* skip comment line */
continue;
else if (0 == strncmp(ptr, KEYWORD, strlen(KEYWORD)) ) /* match KEYWORD */
{
ptr = clearup_string2(ptr+strlen(KEYWORD));
if (ptr){
/* hanle the key */
}
else{
fprintf(stderr, "%s\n", ptr);
}
}
else{
fprintf(stderr, "%s\n", ptr);
}
}
}
}
#include <string.h>
#define KEYWORD "filter"
#define FILTER_FILE "/etc/key_rules.conf"
char *clearup_string1(char *buf)
{
int len;
char ch;
char *ptr;
if (NULL == buf)
return NULL;
/* skip space and tab */
while(*buf)
{
if (*buf == ' ' || *buf == '\t')
buf++;
else
break;
}
if (buf)
ptr = buf;
else
return NULL;
/* skip space and tab, return and new line character */
len = strlen(buf);
while(len){
ch = buf[len-1];
if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n'){
buf[len-1] = '\0';
len--;
}
else{
break;
}
}
return ptr;
}
char *clearup_string2(char *buf)
{
int len;
char ch;
char *ptr;
if (NULL == buf)
return NULL;
/* skip space and tab */
while(*buf)
{
if (*buf == ' ' || *buf == '\t' || *buf == '=' || *buf == '\"')
buf++;
else
break;
}
if (buf)
ptr = buf;
else
return NULL;
/* skip space and tab, return and new line character */
len = strlen(buf);
while(len){
ch = buf[len-1];
if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n' || ch == '=' || ch == '\"'){
buf[len-1] = '\0';
len--;
}
else{
break;
}
}
return ptr;
}
int main()
{
FILE *fp;
char *ptr;
char buf[1024];
fp = fopen(FILTER_FILE, "r");
if (NULL == fp)
{
fprintf(stderr, "fopen fail.\n");
return -1;
}
/* reverse file line by line */
while(fgets(buf, sizeof(buf), fp))
{
if ( NULL != (ptr = clearup_string1(buf)))
{
if (*ptr == '#') /* skip comment line */
continue;
else if (0 == strncmp(ptr, KEYWORD, strlen(KEYWORD)) ) /* match KEYWORD */
{
ptr = clearup_string2(ptr+strlen(KEYWORD));
if (ptr){
/* hanle the key */
}
else{
fprintf(stderr, "%s\n", ptr);
}
}
else{
fprintf(stderr, "%s\n", ptr);
}
}
}
}
0 0
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 处理字符串
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- Hibernate使用sql语句实现多表关联查询
- LinkedHashMap
- IOS URL解码,编码
- LsInventorySession failed: Unable to create patchObject
- 修改ActiveReports验证文字“给不能为 null 的参数指定一个 null 值”
- 字符串处理
- 三极管的工作原理?
- NodeJS express command not found
- java学习笔记(五) -- 字符串
- Effective java1——避免创建不必要的对象
- SQL点滴1—SET QUOTED_IDENTIFIER OFF语句的作用
- linux下cuda开发环境搭建
- 开源代码资源列表
- 关于继承的讨论,以及私有属性继承的问题