时间:2011-12-24 23:48:41
第2套题
一、程序填空题
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void WriteText(FILE *);
void ReadText(FILE *);
main()
{ FILE *fp;
if((fp=fopen("myfile4.txt","w"))==NULL)
{ printf(" open fail!!n"); exit(0); }
WriteText(fp);
fclose(fp);
if((fp=fopen("myfile4.txt","r"))==NULL)
{ printf(" open fail!!n"); exit(0); }
ReadText(fp);
fclose(fp);
}
/**********found**********/
void WriteText(FILE ___1___)
{ char str[81];
printf("nEnter string with -1 to end :n");
gets(str);
while(strcmp(str,"-1")!=0) {
/**********found**********/
fputs(___2___,fw); fputs("n",fw);
gets(str);
}
}
void ReadText(FILE *fr)
{ char str[81];
printf("nRead file and output to screen :n");
fgets(str,81,fr);
while( !feof(fr) ) {
/**********found**********/
printf("%s",___3___);
fgets(str,81,fr);
}
}
二、程序改错题
#include <stdio.h>
/************found************/
void fun (long s, long t)
{ long sl=10;
*t = s % 10;
while ( s > 0)
{ s = s/100;
*t = s%10 * sl + *t;
/************found************/
sl = sl*100;
}
}
main()
{ long s, t;
printf("nPlease enter s:"); scanf("%ld", &s);
fun(s, &t);
printf("The result is: %ldn", t);
}
三、程序编写题
#include <stdio.h>
#define N 16
typedef struct
{ char num[10];
int s;
} STREC;
int fun( STREC *a, STREC *b )
{
}
main()
{ STREC s[N]={{"GA05",85},{"GA03",76},{"GA02",69},{"GA04",85},
{"GA01",91},{"GA07",72},{"GA08",64},{"GA06",87},
{"GA015",85},{"GA013",91},{"GA012",64},{"GA014",91},
{"GA011",91},{"GA017",64},{"GA018",64},{"GA016",72}};
STREC h[N];
int i,n;FILE *out ;
n=fun( s,h );
printf("The %d lowest score :n",n);
for(i=0;i<n; i++)
printf("%s %4dn",h[i].num,h[i].s);
printf("n");
out = fopen("K:\k01\24010001\out.dat","w") ;
fprintf(out, "%dn",n);
for(i=0;i<n; i++)
fprintf(out, "%4dn",h[i].s);
fclose(out);
}