2012年11月3日

对文件存贮结构体变量的一些操作记录及几个错误解决

摘要: 做到第十三章的文件题,做一些记录。#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 3typedef struct student{int num;char name[10];float score[3];float ave;}BT;void main() {FILE *fp,*fp1;BT s[N],s1[N],s3[N+1],s4[N+1],temp;int i,j,n;if((fp=fopen("file","w+"))==0 阅读全文

posted @ 2012-11-03 22:06 天涯古人 阅读(103) 评论(0) 推荐(0) 编辑

2012年11月2日

将链表逆序排列的一个程序及思考的对链表依某一元素排序方法

摘要: 遇到将链表逆序排列的问题,一开始觉得肯定会很复杂,后来猛然想到用数组存放地址程序如下:#include <stdio.h> #include <stdlib.h> #define N 6 typedef struct student {int num; char name[8]; int age; struct student *next; }BT; void main() {BT a[N]={{100,"Lui",20},{101,"Wang",21},{102,"LI",21},{105,"zha 阅读全文

posted @ 2012-11-02 18:53 天涯古人 阅读(217) 评论(0) 推荐(0) 编辑

将一个有序链表和一个无序链表合并,并按序号大小排序

摘要: 这里做的工作有很大局限性:未考虑两链表中序号相同时怎么办;表一必须是有序的,表二可以是无序的,这样能排序;感觉两个都是乱序的很难弄。但调了很久,记下纪念。#include <stdio.h> #include <string.h> #include <stdlib.h> #define LA 4 #define LB 4 #define NULL 0 struct student {int num; char name[8]; struct student *next; }a[LA],b[LB]; void main() {struct student a[ 阅读全文

posted @ 2012-11-02 10:59 天涯古人 阅读(515) 评论(0) 推荐(0) 编辑

2012年10月28日

揭露谭浩强错误二:枚举类型变量不能进行++,--等运算

摘要: 谭老师的《C程序设计》,第314页,程序如下:#include <stdio.h>#include <stdlib.h>void main(){enum color {red,yellow,blue,white,black};enum color i,j,k,pri;int n,loop;n=0;for(i=red;i<=black;i++) for(j=red;j<=black;j++) if(i!=j) { for(k=red;k<=black;k++) if((k!=i)&&(k!=j)) {n=n+1; printf(" 阅读全文

posted @ 2012-10-28 21:29 天涯古人 阅读(753) 评论(0) 推荐(0) 编辑

2012年10月27日

字符串的首地址做形参不能将变化传递回主函数

摘要: 要用指针实现几个字符串按大小排序,有多种方法。可以在主函数中将指向字符串的指针值交换;可以直接用在主函数中用strcpy交换指针指向的字符串;也可以在被调函数中用strcpy交换形参指针指向的字符串。但以下:在被调函数中交换形参指针,这个传不会主函数的。#include <stdio.h>#include <string.h>#include <stdlib.h>void main(){void swap(char *m,char *n,char *p); char str1[20],str2[20],str3[20],*p1,*p2,*p3; gets(s 阅读全文

posted @ 2012-10-27 12:11 天涯古人 阅读(283) 评论(0) 推荐(0) 编辑

2012年10月26日

揭露谭浩强的错误-证实不能用字符指针变量做实参

摘要: 谭浩强 《C程序设计第三版》 第255页 例10.19 有如下程序:功能是将a字符串复制到b,并输出两个字符串。#include<stdlib.h>#include<stdio.h>void copy_string(char *from,char *to){ for(;*from!='\0';) *to++=*from++; *to='\0'; }int main(){char *a="I am teacher.";char *b="you are a student.";printf(" 阅读全文

posted @ 2012-10-26 14:50 天涯古人 阅读(469) 评论(0) 推荐(0) 编辑

导航