69,381
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#define LEN sizeof (struct gzb)
#define MAXLEN 20
struct gzb
{
char name[MAXLEN];
float gz,sanj,gs,sd;
struct gzb *next;
};
float income_tax(float income,float insurance);
void main()
{
FILE *fa,*fb;
char buf[1024];
struct gzb *p1;
/**
** a.txt
**
** 姓名 工资 三金
**
**/
if((fb=fopen("b.txt","w+"))==NULL)
{
printf("cannot open this file\n");
exit(1);
}
fprintf(fb,"姓名 工资 三金 税金 所得工资\n");
if((fa=fopen("a.txt","r"))==NULL)
{
printf("cannot open this a file\n");
exit(1);
}
while(fgets(buf,1024,fa)!=NULL)//此处可以做些技术性出来,是程序根据灵活性
{
p1=(struct gzb*)malloc(sizeof(struct gzb));
sscanf(buf,"%s%f%f",p1->name,&p1->gz,&p1->sanj);
printf("%s %f %f\n",p1->name,p1->gz,p1->sanj);
// p1->gs=income_tax(p1->gz,p1->sanj);
// fprintf(fb,"%s %f %f %f %f\n",p1->name,p1->gz,p1->sanj,p1->gs,p1->gz - p1->sanj - income_tax(p1->gz,p1->sanj));
}
fclose(fa);
fclose(fb);
}
#include <stdio.h>
int main()
{
FILE *infile;
int data;
infile = fopen("e:\\database\\infile.txt","r");
if(!infile)
return -1;
fscanf(infile,"%*[^\n]");/*读取第一行,但是不赋值给任何变量*/
fscanf(infile,"%*s %*s %d",&data);/*读取第二行,只把第三列数据赋值给一个变量*/
printf("%d",data);
return 0;
}
fscanf("%[^\n]",line1);//第一行
fscanf("%s %d %d",a,&b,&c);//第二行