while(scanf(\{
pNode = (struct node*)malloc(sizeof(struct node)); pNode->data = data; pNode->next = NULL;
if (head == NULL) head = tail = pNode; else {
tail->next = pNode; tail = pNode; } }
if (head != NULL)
printf(\
while(head != NULL) {
pNode = head; head = head->next; free(pNode); } }
***************End of Chapter 14******************* 第十五章 位 运 算
************************************************** 一、选择题
(1)D 2)A 3)B 4)A 二、填空题 (5) 11110000 (6) a & 0 (7) a | 1
(8) x | 1111111100000000 (9) a = 012500>>2 10)ch | 32
***************End of Chapter 15******************* 第十六章 文 件
************************************************** 一、选择题 (1) B (2) C 二、填空题
(3) 3 , f1! = f2 , f2 , fclose (f1) , fclose(f2)
(4) fopen(fname,\
(5) \ (6) AAAABBBBCCCC 三、编程题
——————————————————————————————————————
16.7 请调用fputs函数,把10个字符串输出到文件中,再从此文件中读入这10个字符串放在一个字符串数组中;最后把字符串数组中的字符串输出到终端屏幕,以检验所有操作是否正确。 #include main() { int i; char s[100]; FILE *fp;
if((fp=fopen(\{
printf(\exit(0); }
for(i=0;i<10;i++) { gets(s); fputs(s,fp); fprintf(fp,\}
rewind(fp); for(i=0;i<10;i++) {
fgets(s,100,fp); printf(\} fclose(fp); }
——————————————————————————————————————
16.8 从键盘输入10个浮点数,以二进制形式存入文件中。再从文件中读出数据显示在屏幕上。修改文件中第四个数。再从文件中读出数据显示在屏幕上,以检验修改是否正确。 ※程序如下※ #include main() { int i;
float n,a[10],b[10]; FILE *fp; clrscr();
printf(\
if((fp=fopen(\{
printf(\exit(0); }
for(i=0;i<10;i++) {
scanf(\fwrite(&n,4,1,fp); }
rewind(fp); /*是文件指针指向文件开始*/ printf(\for(i=0;i<10;i++) {
fread(&a,4,1,fp); /* 从文件中读出数据存入数组*/ printf(\}
printf(\scanf(\
fseek(fp,3*4L,SEEK_SET); /*使文件指针指向第四个数*/ fwrite(&n,4,1,fp); rewind(fp); for(i=0;i<10;i++) {
fread(&b,4,1,fp); printf(\} fclose(fp); }
***************End of Chapter 16*******************