- 博客(22)
- 资源 (1)
- 收藏
- 关注
原创 文件与结构体
#define _CRT_SECURE_NO_WARNINGS#include#define LEN 3struct Student{int num;char name[20];int age;char addr[15];}stu[LEN]; //定义全局结构体数组;void save(struct Student stud[]){FILE
2015-12-28 17:06:00
594
原创 枚举类型简单例子
//枚举类型例子#includeint main(){enum Color {red ,yellow,blue,white,black };//声明枚举类型enum Colorint i, j, k, pri;//定义枚举变量int n, loop;n = 0;for (i = red; i for (j = red; j if (i != j)//如果两
2015-12-17 19:00:02
3144
原创 共用体简单例子
//共用体例子#define _CRT_SECURE_NO_WARNINGS#include//声明无名的结构体类型struct{int num;//成员编号char name[20];//成员姓名char sex;//成员性别char job;//成员职业union //声明无名的共用体类型{int clas;//成员班级char pos
2015-12-17 11:13:17
1235
原创 结构体例题汇总
例一://///结构体变量初始化和引用#includeint main(){ structStudent { longintnum; charname[20]; charsex; char
2015-12-16 21:29:02
3932
原创 若干个字符串排序,然后写到文件中
#define_CRT_SECURE_NO_WARNINGS#include#include#include#define LINE 3int main(){ charstr[LINE][10]={0}; inti = 0 ; chartemp[10] = {0} ; intm = 0 , n
2015-12-13 21:25:26
1376
原创 文件读写操作
这个程序把一个文件中的数据有选择地复制到另一个文件中,它同时打开两个文件,程序通过只保留每三个字符的第三个来压缩文件内容,最后把压缩后的文本写入第二个文件中。#define _CRT_SECURE_NO_WARNINGS#include#include#includeint main(int argc ,char *argv[]){FILE *in, *out;in
2015-12-12 12:03:47
320
原创 分配内存空间
#include#include#Include>char *getstr();int main(){char *p=NULL;p = getstr();puts(p);free(p);return 0 ;}char *getstr(){char *str=NULL;str = (char * )malloc(sizeof(char)*5
2015-12-05 14:14:22
295
原创 矩阵的转置
#includeint main(){void transpose(int (*pt1)[3], int (*pt2)[3]);int a[3][3];int (*p1)[3]=a;//定义一个指针变量,指向包含3个元素的一维数组的指针变量;int b[3][3];int (*p2)[3]=b;int i = 0, j = 0;for (i = 0; i f
2015-12-04 20:50:52
391
原创 统计大写,小写,数字等个数
#include#includeint main(){void statistics(char *pt);char str[100];int i = 0;while ((str[i] = getchar()) != '\n')i++;char *p = &str[0];statistics(p);return 0;}void statistics
2015-12-04 18:09:15
471
原创 一个包含n个字符的字符串,从第m个字符开始复制成为另外一个字符串
/////一个包含n个字符的字符串,从第m个字符开始复制成为另外一个字符串//////////#include#includeint main(){void copystr(char *pt1, char *pt2, int number);char str1[20];char str2[20];printf("input string:\n");gets_s(
2015-12-04 17:40:12
2108
原创 the length of the string
#includeint length(char *pt);int main(){char a[100];char *p=a;printf("input string:");gets_s(a);int l;l=length(p);printf("the length of the string is %d\n", l);return 0;}int
2015-12-04 16:57:54
937
原创 n个人围成一圈,顺序排号
/////n个人围成一圈,顺序排号,从第一个人开始报数,报到指定的数时推出圈子,问最后留下的是原来第几号的那位#include#define N 8#define M 3int main(){int a[N];for (int i = 0; i a[i] = i+1;int *p = a;int j = 0;//设置每次循环时计数变量,范围是0—N-1;
2015-12-04 11:48:41
612
原创 有N个整数,利用指针使前面各数顺序向后移M个位置
///////////////////有N个整数,使前面各数顺序向后移M个位置////////////////////#include#define N 10#define M 3int main(){void adjust(int *pt, int n, int m);int a[N];for (int i = 0; i scanf_s("%d", &a[i]
2015-12-03 22:39:52
3616
原创 对于整数的处理(最小的与第一个交换,最大的与最后一个交换)
#includeint main(){void input(int *pt, int number);void print(int *pt, int number);void process(int *pt, int number);int a[10];int *p = a;int n = 5;printf("enter %d numbers:\n", n);
2015-12-03 22:04:28
513
原创 利用指针对字符串排序
#include#includeint main(){void sort(char *pt[], int number);void print(char *pt[], int number);char str[3][20] = {0}; //这里的0不是数字0,而是字符0,代表的含义是'\0'(空字符);char *p[3]; //定义一个数组
2015-12-03 20:20:36
3344
2
原创 输入三个整数,从小到大的顺序输出(利用指针)
#includeint main(){void fun(int *p1, int *p2, int *p3);int a, b, c;printf("enter three numbers :\n");scanf_s("%d%d%d", &a, &b, &c);fun( &a, &b, &c);return 0;}void fun(int *p1, int
2015-12-02 22:10:09
18506
1
原创 void 指针类型例子
///////内存动态分配区和使用void 指针///////////////////程序中没有定义数组,而是开辟一段动态自由分配区,作为动态数组使用//调用malloc函数的返回值是 void * 型的,要先把它赋给P1,进行类型转换//把该指针转换成 int * 型;#include#include //程序中含有malloc函数,应包含stdlib.hint m
2015-12-02 20:22:18
524
原创 指向指针的指针(2)
////////////指针数组的元素指向整型数组的元素///////////#includeint main(){int a[5] = { 1, 2, 3, 4, 5 };int *name[5] = { &a[0], &a[1], &a[2], &a[3], &a[4] };int **p;p = name;for (int i = 0; i {prin
2015-11-30 20:50:30
293
原创 指向指针数据的指针变量
#includeint main(){char *name[] = { "follow me", "basic", "great wall", "fortran", "computer design" };//定义一个指针数组;char **p;//p是指向char*型数据的指针变量,即指向指针的指针;int i;for (i = 0; i {p = nam
2015-11-30 20:28:43
639
1
原创 利用指针数组实现将若干字符串按照字母顺序输出
/////////利用指针数组实现将若干字符串按照字母顺序输出///////////#include#includeint main(){void sort( char *name[], int n);void print(char *name[], int n);char *name[5] = { "follow me", "basic", "great wall",
2015-11-30 16:31:49
2540
原创 利用指针找出不及格学生的成绩
#includeint main(){int *search(int (*pointer)[4]);int *p;int score[4][4] = { { 60, 85, 78, 89 }, {59, 89, 88, 99 }, { 78, 89, 89, 50 }, { 60, 85, 95, 20 } };int i, j;for (i = 0; i {p
2015-11-30 15:38:29
1507
原创 利用返回指针值的函数进行查找学生的成绩
#includeint main(){int *search(int(*pointer)[4], int number);int *p;int k;int score[][4] = { { 45, 85, 78, 89 }, { 78, 89, 88, 99 }, { 78, 89, 89, 50 }, { 60, 85, 95, 20 } };printf("ente
2015-11-30 15:18:21
423
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人