易截截图软件、单文件、免安装、纯绿色、仅160KB

C/C++中结构体(struct)知识点强化(二)

C/C++中结构体(struct)知识点强化(二)
出处:PConline 2005年03月07日 作者:管宁 责任编辑:xietaoming
 
  首先,我们写这个程序,要考虑到由于是一个链表结构,我们不可能知道它的大小到底是多大,这个问题我们可以用动态开辟堆内存来解决,因为堆内存在程序结束前始终是有效的,不受函数栈空间生命期的限制,但要注意的是我们必须有一个指针变量来存储这一链状结构的进入地址,而在函数内部来建立这一指针变量显然是不合适的,因为函数一旦退出,这个指针变量也随之失效,所以我们在程序的开始声明了一个全局指针变量。
test *head;//创建一个全局的引导进入链表的指针
  好解决了这两个问题,我们接下去思考
  有输入就必然有输出,由于输出函数和输入函数是相对独立的,为了不断测试程序的正确性好调试我们先写好输出函数和main函数捏的调用,创建函数我们先约定好名为create。
  我们先写出如下的代码:
#include <iostream> 
using namespace std; 
 
struct test 

    char name[10]; 
    float socre; 
    test *next; 
}; 
 
test *head;//创建一个全局的引导进入链表的指针 
 
test *create() 

 
    return head;//返回链首指针 

 
void showl(test *head) 

    cout<<"链首指针:"<<head<<endl; 
    while(head)//以内存指向为null为条件循环显示先前输入的内容 
    { 
        cout<<head->name<<"|"<<head->socre<<endl; 
        head=head->next; 
    } 

 
void main() 

    showl(create()); 
    cin.get(); 
    cin.get(); 
}
  程序写到这里,基本形态已经出来,输入


相关文档:

c/c++读写文件

#include<stdlib.h>
#include<iostream>
#include<string.h>
using namespace std;
int main(void)
{
FILE *fp, *fp2;
char buf[1024*300];
fp = fopen("in.txt", "rb");
fp2 = fopen("out.txt", "wb+");
fseek(fp, 0, SEEK_END);
int iLen ......

C 字符串函数大全

函数名: stpcpy
功 能: 拷贝一个字符串到另一个
用 法: char *stpcpy(char *destin, char *source);
程序例:
#include <stdio.h>
#include <string.h>
int main(void)
{
   char string[10];
   char *str1 = "abcdefghi";
   stpcpy(string, str1);
 & ......

C打印 大数的 阶乘

 6000甚至10000,都可以,但大于6000,就开始滚屏了。。
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){
int i,j,*f,tmp,c=0;
long int n,bits;
const double PI=2*asin(1.0),E=exp(1.0);
scanf("%ld",&n);
bits=(long)ceil(n*(log10(n)-log ......

用php的c扩展编程调用 c程序的动态链接库


一.    首先做一个简单的so文件:
    /**
     * hello.c
     * To compile, use following commands:
     *   gcc -O -c -fPIC -o hello.o hello.c
     *   gcc -shared ......

简单的素数判断C程序

仅供学习使用:
/*********************************************
 * Name : prime.c
 * Purpose : prime (素数判断)
 * Author : zimo
 * Date : 01/21/2010
 * ******************************************/
#include<stdio.h>
int main()
{
    int m , n ;
& ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号