RE:整数相除的问题和显示问题?
pvii 2005-11-26 11:10:11 整数相除的问题和显示问题?
代码如下
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <malloc.h>
#include <assert.h>
#define LEN 20// 节点的个数
typedef struct _node
{
int k;
int w;
int v;
double vper;
}Node;
Node list[LEN];
void show(const char* title)
{
int i;
if( title != NULL )
{
printf("%s\n",title);
}
for( i = 0 ; i < LEN ; i++ )
{
printf("k:%d\tw:%d\tv:%d\tvper%f\n",list[i].k,list[i].w,list[i].v,list[i].vper);// 问题这里为什么有的list[i].vper 为0.000000?
}
printf("\n");
}
void init()
{
FILE *fp;
char* buf1 = (char*)malloc(50*sizeof(char));
char* buf2 = (char*)malloc(50*sizeof(char));
int i=0;
fp = fopen("data.dat","r");
assert( fp!=NULL);
if( fp != NULL )
{
while( !feof(fp))
{
fscanf(fp,"%s %s\n",buf1,buf2);
if( i < LEN)
{
list[i].k = i;
list[i].w = atoi(buf1);
list[i].v = atoi(buf2);
list[i].vper = list[i].v/list[i].w;//这里可能出问题
i++;
}
}
}
free(buf1);
free(buf2);
show();
}
void main()
{
init():
}
data.dat
533 310
351 834
908 789
554 235
688 475
362 1005
722 216
597 333
300 593
230 995
660 949
856 116
212 760
648 827
496 844
817 29
958 176
151 300
79 513
421 241