首页 > 其他 > 详细

92自己动手实现分割文本

时间:2018-05-25 01:15:09      阅读:232      评论:0      收藏:0      [点我收藏+]

#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\n",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\n",name , age);


}
}

fclose(read);

system("pause");

}

92自己动手实现分割文本

原文:https://www.cnblogs.com/xiaodaxiaonao/p/9085884.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!