#cat  /tmp/fff
10:hugetlb:/hello/06b11c9967cc0e106f5f4673246f671aa7388f623f58b250d9d9cb0f8c0f2b18
9:devices:/hello/06b11c9967cc0e106f5f4673246f671aa7388f623f58b250d9d9cb0f8c0f2b18
8:perf_event:/hello/06b11c9967cc0e106f5f4673246f671aa7388f623f58b250d9d9cb0f8c0f2b18
7:cpuacct,cpu,cpuset:/hello/06b11c9967cc0e106f5f4673246f671aa7388f623f58b250d9d9cb0f8c0f2b18
6:memory:/hello/06b11c9967cc0e106f5f4673246f671aa7388f623f58b250d9d9cb0f8c0f2b18
4:freezer:/hello/06b11c9967cc0e106f5f4673246f671aa7388f623f58b250d9d9cb0f8c0f2b18
3:intel_rdt:/hello/06b11c9967cc0e106f5f4673246f671aa7388f623f58b250d9d9cb0f8c0f2b18
2:blkio:/hello/06b11c9967cc0e106f5f4673246f671aa7388f623f58b250d9d9cb0f8c0f2b18
1:name=systemd:/hello/06b11c9967cc0e106f5f4673246f671aa7388f623f58b250d9d9cb0f8c0f2b18
#cat gg.c
#include <stdio.h>
#include <string.h>
#include <errno.h>
int main()
{
char filename[] = "/tmp/fff";
FILE *fp = NULL;
char newline[128];
char *keyword = "cpuset";
char final1[64];
char *delim = "/";
char *p = NULL;
char final2[12];
int length = 12; if((fp = fopen(filename,"r")) == NULL)
{
printf("error!");
return -1;
} while (!feof(fp))
{
fgets(newline, 128, fp); if (strstr(newline, keyword)) {
strtok(newline, delim);
while((p = strtok(NULL, delim))) {
strcpy(final1, p);
}
printf("final1:%s\n", final1);
break;
}
} strncpy(final2, final1, length);
printf("final2:%s\n", final2);
fclose(fp);
return 0;
}
#./gg
final1:06b11c9967cc0e106f5f4673246f671aa7388f623f58b250d9d9cb0f8c0f2b18 final2:06b11c9967cc

C 利用strtok, feof 截取字符串的更多相关文章

  1. C#利用String类的IndexOf、LastIndexOf、Substring截取字符串

    一.String.IndexOf String.IndexOf 方法 (Char, Int32, Int32)报告指定字符在此实例中的第一个匹配项的索引(从0开始).搜索从指定字符位置开始,并检查指定 ...

  2. C# 截取字符串

    1.根据单个分隔字符用split截取 例如 string st="GT123_1"; string[] sArray=st.split("_"); 即可得到sA ...

  3. C#中截取字符串的几种方法

      1.根据单个分隔字符用split截取 例如 复制代码代码如下: string st="GT123_1"; string[] sArray=st.split("_&qu ...

  4. C#几种截取字符串的方法小结

    1.根据单个分隔字符用split截取例如代码如下: string st="GT123_1"; string[] sArray=st.split("_"); 即可 ...

  5. C#截取字符串的方法小结

    1.根据单个分隔字符用split截取 string st="GT123_1"; string[] sArray=st.split("_"); 输出:sArray ...

  6. js截取字符串区分汉字字母代码

    js截取字符串并且区分汉字字母,一个汉字辨别为两个字节. function substr(str, len) { if (!str || !len) { return ''; } // 预期计数:中文 ...

  7. C#几种截取字符串的方法小结,需要的朋友可以参考一下

    1.根据单个分隔字符用split截取 例如 复制代码 代码如下: string st="GT123_1"; string[] sArray=st.split("_&quo ...

  8. C#几种截取字符串的方法小结 (摘抄)

    1.根据单个分隔字符用split截取 例如 string st="GT123_1"; string[] sArray=st.split("_"); 即可得到sA ...

  9. SQL截取字符串

    SUBSTRING 返回字符.binary.text      或      image      表达式的一部分.有关可与该函数一起使用的有效      Microsoft®      SQL    ...

随机推荐

  1. hdu 5950 Recursive sequence

    题意:告诉你数列的递推公式为f(n+1)=f(n)+2*f(n-1)+(n+1)^4 以及前两项a,b:问第n项为多少,结果对2147493647取模. 题解:有递推公式,马上应该就能想到矩阵快速幂: ...

  2. [WebGL入门]二十一,从平行光源发出的光

    注:文章译自http://wgld.org/,原作者杉本雅広(doxas),文章中假设有我的额外说明.我会加上[lufy:],另外,鄙人webgl研究还不够深入,一些专业词语.假设翻译有误,欢迎大家指 ...

  3. LeetCode 645. Set Mismatch (集合不匹配)

    The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of ...

  4. 怎样对Android设备进行网络抓包

    问题描写叙述: 前段时间自己的app訪问server的url总是会出现间接性失败的问题,于是和server的同事开了个会.提出了他们server存在的这个bug,我的同事自然说自己的server没问题 ...

  5. HDU5501/BestCoder Round #59 (div.2)The Highest Mark dp+贪心

    The Highest Mark 问题描述 2045年的SD省队选拔,赛制和三十年前已是完全不同.一场比赛的比赛时间有 tt 分钟,有 nn 道题目. 第 ii 道题目的初始分值为 A_i(A_i \ ...

  6. java.io.IOException: The same input jar is specified twice

    简介: eclipse android proguard 打包时出现 java.io.IOException: The same input jar is specified twice 错误, 这里 ...

  7. golang函数——可以为类型(包括内置数据类型)定义函数,类似类方法,同时支持多返回值

    不可或缺的函数,在Go中定义函数的方式如下: func (p myType ) funcName ( a, b int , c string ) ( r , s int ) { return } 通过 ...

  8. bzoj2300

    http://www.lydsy.com/JudgeOnline/problem.php?id=2300 终于对了... 平衡树又写挂了...不要忘记清空原先的root和修改root... #incl ...

  9. Request returned failure status 401

    Request returned failure status 401.Invalid OpenStack Identity credentials.

  10. 红黑树插入操作原理及java实现

    红黑树是一种二叉平衡查找树,每个结点上有一个存储位来表示结点的颜色,可以是RED或BLACK.红黑树具有以下性质: (1) 每个结点是红色或是黑色 (2) 根结点是黑色的 (3) 如果一个结点是红色的 ...