当前位置: 代码迷 >> C语言 >> 文件总是调用不到,怎么办?急!
  详细解决方案

文件总是调用不到,怎么办?急!

热度:143   发布时间:2008-05-10 18:32:05.0
文件总是调用不到,怎么办?急!
#include<stdlib.h>
#include<stdio.h>
typedef struct push
{
int num;
double d,D,DT,DL,D1,L1,L2;
struct push *next;
}PUSH;

PUSH *input_data(void)
{FILE *fp; int n;
char name[10];
PUSH *ptr,*head,*this;
printf("input file name of GB: \n");
printf("Name: ");
scanf("%s", name);
if(fp=fopen("name","r")==NULL)
{
printf("cannot open the data file \n");
exit(1);
}
fscanf(fp,"%*S%*S%*S%*S%*S%*S%*S%*S");
head=NULL;
fscanf(fp,"%d",&n);
while(n!=-1)
{
ptr=(PUSH*)malloc(sizeof(PUSH));
if(ptr==NULL)
{printf("no enough memory!\n");
exit(1);
}
if(head==NULL)
head=ptr;
else
this->next=ptr;
this=ptr;
this->next=head;
this->num=n;
fscanf(fp,"%lf,%lf,%lf,%lf,%lf,%lf,%lf",&(this->d),&(this->D),&(this->DT),&(this->DL),&(this->D1),&(this->L1),&(this->L2));
fscanf(fp,"%d",&n);
}
this=head;
return(head);
fclose(fp);
}

void main(void)
{
PUSH *this *head;
int n,no;
n=0;
this=input_data();
do
{
n=n+1;
printf("%d\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t\n",n,this->d,this->D,this->DT,this->DL,this->D1,this->L1,this->L2);
this=this->next;
}while(this!=head);
printf("please chose No.Parameter\n");
printf("No=\n");
scanf("%d",&no);
this=head;
do{
   n=this->num;
   if(n==no)
   {
    printf("%d\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t\n",no,this->d,this->D,this->DL,this->D1,this->L1,this->L2);
    break;
   }
   this=this->next;
  }while(this!=head);
}
我要调用的文件是GB123.dat,不知道是这个文件放的地方不对还是程序本身有问题,大家帮忙解决下哈,谢谢了
搜索更多相关的解决方案: PUSH  name  文件  ptr  

----------------解决方案--------------------------------------------------------
  相关解决方案