佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 940|回复: 1

C programming Open a file

[复制链接]
发表于 27-10-2008 04:49 PM | 显示全部楼层 |阅读模式
嗨,
我的 Load function  有问题,  谁可以帮我修改。
load function 那边是想打开 txt file  然后display成这样

pit location                        pit depth
---------------                        ------------
Bear-Track 01                 -5.18
Bear-Track 03                 -32.30
Bear-Track 04                 -2.34



#include <stdbool.h>
#include <stdlib.h>

void load(char, int);
double depth(double seconds2Bottom);
void menuSelect(char selection);
bool yesNo(const char prompt[]);

int main(void)
{
char selection;
double toBottom;
char name;
//char repeat;

printf("(D)epth: Enter pit location. Compute depth \n");
printf("(S)ave : Write pits date to file \n");
printf("(L)oad : Read mine shaft information from file. \n");
printf("(P)rint: Display mine shaft information.\n");
printf("(Q)uit : Exit program.\n\n");
printf("Enter your choice (D/S/L/P/Q): ");

scanf("%c", &selection);
menuSelect(selection);
/*
    if((selection) !='d' && (selection) != 'D')
printf("invalid entry");
else
while(1);
*/

  /* Time to reach the bottom of the shaft */
do
{
     printf("Entermine shaft location or name:");
  scanf("%s", &name);
  printf("\nEnter time to bottom: ");
  scanf("%lf", &toBottom);
  fflush(stdin);
  printf("\nShaft depth is %.2f m\n", depth(toBottom));
  
} while( yesNo("Do you want to take another measure"));
return 0;
}
double depth(double seconds2Bottom)
{
/* Acceleration of gravity */
const double G = 9.81;
   

return -0.5 * G * seconds2Bottom * seconds2Bottom;
  
}
void load(char name, int seconds)
{
   FILE *loadFile;
   
   
loadFile = fopen("Bear-Eldorado.pit", "w");
if (loadFile==NULL)
exit(1);
fprintf(loadFile, "%s %i\n", name, seconds);
fclose(loadFile);
return;

}

void menuSelect(char selection)
{
double seconds2Bottom;
char name;
int seconds;
switch(selection)
{
case 'd':
case 'D':
depth(seconds2Bottom);
break;
case 'l':
case 'L':
open(name, seconds);
break;
case 'q':
case 'Q':
exit(0);
}
}

bool yesNo(const char prompt[])
{
char answer;
printf("\n%s (Y/N)? ", prompt);
answer = getchar();
fflush(stdin);
return (answer == 'y' || answer == 'Y');
}
回复

使用道具 举报


ADVERTISEMENT

发表于 27-10-2008 09:40 PM | 显示全部楼层
load的用途是从txt file读取资料吧?
你写的是load是写入资料喔
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 22-12-2025 07:22 AM , Processed in 0.113301 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表