求高手帮忙!!!C语言的问题!!

来源:百度知道 编辑:UC知道 时间:2024/06/19 16:11:11
#include<stdio.h>
#include<stdlib.h>
struct student
{
int num;
char name[20];
float score[5];
int mingci;
}student[5];
void main()
{
FILE *fp;
int i,j,n;
float max,a;
char b[20]="The average is ";
if((fp=fopen("stud","w"))==NULL)
{ printf("cannot open file\n");
exit(0);
}
for(i=0;i<5;i++)
{ student[i].score[4]=0;
scanf("%d%s",&student[i].num,student[i].name);
for(j=0;j<4;j++)
scanf("%f",&student[i].score[j]);
}
for(i=0;i<5;i++)
if(fwrite(&student[i],sizeof(struct student),1,fp)!=1)
printf("file write error\n");
for(i=0;i<4;i++)
{ for(j=0;j<4;j++)
student[i].score[4]=student[i].score[4]+student[i].score[j];
if(student[i].score[4]>max)
{ max=

浮点数没有链接,主要是是由于以前内存小引起的.
你应当用的是TUBOC编译器.

你可以在

FILE *fp;
int i,j,n;
float max,a;

后面加一行:
float *p=&max;
应当就可以了。
先试吧,不行的话,再说。

我觉得应该这样:扫描文章,构造单词表(单词表有单词和单词出现次数组成);
扫描文章时,读到空格,将前面的单词记下,同时查找单词表,如果此时单词表中已经有了这个单词,将该单词的出现次数加一,如果单词表中没有此单词,向单词表中加入这个单词,.
按字母顺序打印出单词表
我用C++写的,给你一个参考,你的文本文件要与这个程序放在一块,然后在命令行下输入完整的文件名,如:Word.txt
#include <iostream.h>
#include <stdio.h>
#include <string>
#include <map>
using namespace std;

void ReadFromFile()
{
/* this function aimed to read words
from a given file
*/
char sFileName[100];
string sWord;
char ch;
map<string,int> mWordMap;
cout<<"please Enter file name:"<<endl;
bool bContact = false;
/*please make sure that the file is the
same directory with the exe program
*/
cin>>sFileName;