统计Txt中数字个数 并存入链表
来源:互联网 发布:linux 开机自启动脚本 编辑:程序博客网 时间:2024/06/06 11:46
/********************************************************************
/*功能:统计txt文件中16进制数字个数。PS最后一个数字后不能有空格,数字之间是空格不是逗号
/*日期:160816
/*作者:
/*结论:
/*******************************************************************/
#include<stdio.h>
#include <stdlib.h> /*含ma l l o c ( ) 的头文件*/
//链表定义
struct Str_LianBiao
{
int num;
struct Str_LianBiao * next;
};
//链表创建函数声明
struct Str_LianBiao *creat();
void print(struct Str_LianBiao *head);
int main()
{
struct Str_LianBiao *head;
head=NULL;//创建一个空链表
struct Str_LianBiao *p1, *p2;
p1=p2=(struct Str_LianBiao *)malloc(sizeof(struct Str_LianBiao));////利用malloc ( )函数向系统申请分配一个节点
p1->next=NULL; ///*将新节点的指针置为空*/
int data2;
int num=0;
FILE *fp=fopen("待读取数据.txt","r");
//FILE *fp=fopen("D:\\待读取数据.txt","r");
if(!fp)
{
printf("Can't open file!\n");
return -1;
}
while(!feof(fp))
{
fscanf(fp,"%x", &data2);
printf("%d ",data2);
num++;
p1->num=data2; //将数据写入链表中
if(head==NULL)
{
head=p1; //空表,接入表头
}
else
{
p2->next=p1; //非空表,接入表尾部。
}
p2=p1;
p1=(struct Str_LianBiao*)malloc(sizeof(struct Str_LianBiao));/*下一个新节点*/
}
free(p1); //申请到的没录入,所以释放掉
p1=NULL; //使指向空
p2->next = NULL; //到表尾了,指向空
printf("链表输入结束(END)\n");
print(head);/*打印单链表*/
printf("\nThe number is: %d ", num);
fclose(fp);
/*********************输出打印*************************/
char ShuChuDaYin[]="Shu Chu is OK!!!!";
printf("\n%s\n", ShuChuDaYin);
return 0;
}
void print(struct Str_LianBiao *head)/*出以head为头的链表各节点的值*/
{
struct Str_LianBiao *temp;
temp=head;/*取得链表的头指针*/
printf("\n\n\n链表存入的值为:\n");
while(temp!=NULL)/*只要是非空表*/
{
printf("%6d\n",temp->num);/*输出链表节点的值*/
temp=temp->next;/*跟踪链表增长*/
}
printf("链表打印结束!!");
}
/*功能:统计txt文件中16进制数字个数。PS最后一个数字后不能有空格,数字之间是空格不是逗号
/*日期:160816
/*作者:
/*结论:
/*******************************************************************/
#include<stdio.h>
#include <stdlib.h> /*含ma l l o c ( ) 的头文件*/
//链表定义
struct Str_LianBiao
{
int num;
struct Str_LianBiao * next;
};
//链表创建函数声明
struct Str_LianBiao *creat();
void print(struct Str_LianBiao *head);
int main()
{
struct Str_LianBiao *head;
head=NULL;//创建一个空链表
struct Str_LianBiao *p1, *p2;
p1=p2=(struct Str_LianBiao *)malloc(sizeof(struct Str_LianBiao));////利用malloc ( )函数向系统申请分配一个节点
p1->next=NULL; ///*将新节点的指针置为空*/
int data2;
int num=0;
FILE *fp=fopen("待读取数据.txt","r");
//FILE *fp=fopen("D:\\待读取数据.txt","r");
if(!fp)
{
printf("Can't open file!\n");
return -1;
}
while(!feof(fp))
{
fscanf(fp,"%x", &data2);
printf("%d ",data2);
num++;
p1->num=data2; //将数据写入链表中
if(head==NULL)
{
head=p1; //空表,接入表头
}
else
{
p2->next=p1; //非空表,接入表尾部。
}
p2=p1;
p1=(struct Str_LianBiao*)malloc(sizeof(struct Str_LianBiao));/*下一个新节点*/
}
free(p1); //申请到的没录入,所以释放掉
p1=NULL; //使指向空
p2->next = NULL; //到表尾了,指向空
printf("链表输入结束(END)\n");
print(head);/*打印单链表*/
printf("\nThe number is: %d ", num);
fclose(fp);
/*********************输出打印*************************/
char ShuChuDaYin[]="Shu Chu is OK!!!!";
printf("\n%s\n", ShuChuDaYin);
return 0;
}
void print(struct Str_LianBiao *head)/*出以head为头的链表各节点的值*/
{
struct Str_LianBiao *temp;
temp=head;/*取得链表的头指针*/
printf("\n\n\n链表存入的值为:\n");
while(temp!=NULL)/*只要是非空表*/
{
printf("%6d\n",temp->num);/*输出链表节点的值*/
temp=temp->next;/*跟踪链表增长*/
}
printf("链表打印结束!!");
}
0 0
- 统计Txt中数字个数 并存入链表
- 统计Txt文件中数字的个数
- 统计字符串中字母、数字、空格个数
- 统计一个字符串中数字的个数
- Java初级练习--读入txt中字符串个数统计
- 【ThinkingInC++】4、统计txt文本中单词的个数
- 统计产生数字个数
- 数字个数统计
- 如何统计一串数字中,出现重复数的个数?
- 经典:统计字符串中汉字,英文,数字,特殊符号个数
- 统计字符串中每个字母以及数字的个数!
- 16周:统计字符串中数字、字母出现的个数。
- c++builder统计一个字符串中数字的个数
- 统计已知字符串str中数字的个数
- java统计一个字符串中中文,英文,数字的个数
- 统计一个数字二进制中一的个数。
- 黑马程序员--OC统计字符串中数字个数的方法
- 杭电acm 2017统计字符串中数字的个数
- OJ 2754 八皇后
- Codeforces 148D Bag of mice 简单概率dp
- 【JSON】JSON初了解
- Java中变量的种类、变量的初始值
- car (CF 581E)
- 统计Txt中数字个数 并存入链表
- K-means算法原理以及应用(R)
- Android Fragment 基本介绍
- 神编辑器Sublime Text运行java、javascript、python
- HDU 5832 A water problem【大数问题】
- [BZOJ2119]股市的预测(后缀数组+st)
- android实现文件的拖拽效果
- LeetCode 344: Reverse String 题解
- 设计模式C++实现——抽象工厂模式