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");

    }

  • 相关阅读:
    SQL CREATE TABLE 语句
    SQL CREATE DATABASE 语句
    SQL INSERT INTO SELECT 语句
    SQL SELECT INTO 语句
    Why is chkconfig no longer available in Ubuntu?
    drag-html
    js利用offsetWidth和clientWidth来计算滚动条的宽度
    procomm plus
    很多shell命令后面的单横杠和双横杠,原来这个意思
    angular md-toast 颜色
  • 原文地址:https://www.cnblogs.com/xiaodaxiaonao/p/9085884.html
Copyright © 2011-2022 走看看