zoukankan      html  css  js  c++  java
  • 92自己动手实现分割文本

    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    char * my_strtok(char * p_string, char * p_delimiter) {
    static char * p = NULL;
    if (p_string != NULL) {
    p = p_string;
    int l_length = strlen(p_string);
    for (size_t i = 0; i < l_length; i++) {
    if (p_string[i] == p_delimiter[0]) {
    p_string[i] = 0;
    }
    }
    return p;
    }
    else {
    while (*p != 0) {
    p++;
    }
    p++;
    return p;
    }
    }


    void main() {
    FILE*read = fopen("1.txt", "r");
    if (!read) {
    printf("文件为空");
    system("pause");
    return;
    }

    int kong = NULL;
    int xiaomiao = NULL;
    while (!feof(read)) {
    char shuju[20] = { NULL };

    fgets(shuju, sizeof(shuju), read);
    int shaomiao = ftell(read);
    if (shaomiao != kong) {

    char*p = my_strtok(shuju, ",");
    char name[20] = { NULL };
    strcpy(name, p);
    p = strtok(NULL, "NULL");//指针会自动移动
    int age = atoi(p);
    printf("名字%s 年龄%d ",name , age);


    }
    }

    fclose(read);

    system("pause");

    }

    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    void main() {
    FILE*read = fopen("1.txt", "r");
    if (!read) {
    printf("文件为空");
    system("pause");
    return;
    }

    int kong = NULL;
    int xiaomiao = NULL;
    while (!feof(read)) {
    char shuju[20] = { NULL };

    fgets(shuju, sizeof(shuju), read);
    int shaomiao = ftell(read);
    if (shaomiao != kong) {

    char*p = strtok(shuju, ",");
    char name[20] = { NULL };
    strcpy(name, p);
    p = strtok(NULL, "NULL");//指针会自动移动
    int age = atoi(p);
    printf("名字%s 年龄%d ",name , age);


    }
    }

    fclose(read);

    system("pause");

    }

  • 相关阅读:
    方法中的散列可变参数
    方法中的散列可变参数
    策略模式
    策略模式
    HashSet,TreeSet
    HashSet,TreeSet
    ArrayList和LinkedList
    ArrayList和LinkedList
    关于鼠标悬浮标签元素效果(CSS:cursor属性)
    关于鼠标悬浮标签元素效果(CSS:cursor属性)
  • 原文地址:https://www.cnblogs.com/xiaodaxiaonao/p/9085884.html
Copyright © 2011-2022 走看看