#include <stdio.h>
#include 
<stdlib.h>
#include
<string.h>

typedef 
struct{
    
int number;
    
char *msg;
} unit_t;

int main(void) {
    
// 使用 malloc 分配内存, 使用free释放内存,并设置为NULL 杜绝野指针
    unit_t *p=malloc(sizeof(unit_t));
    p
->number=10;
    p
->msg=malloc(10);
    strcpy(p
->msg,"hello");
    printf(
"number is %i \n",p->number);
    printf(
"msg is %s \n",p->msg);
    
//如果先free(p),p成了野指针,就不能再通过p->msg访问内存
    free(p->msg);
    free(p);
    
//如果 free(p)  两次, 则会引发系统错误,
    p=NULL;

    
if(p==NULL){
        printf(
"p point is empty");
        exit(
-1);
    }

    
return EXIT_SUCCESS;
}

posted @ 2011-05-16 13:42 xsong 阅读(160) | 评论 (0)编辑 收藏

/*数组和指针
* 在函数原型中,如果参数是数组,则等价于参数是指针的形式,例如:
void func(int a[10])
{

}
等价于:

void func(int *a)
{

}
第一种形式方括号中的数字可以不写,仍然是等价的:

void func(int a[])
{

}
*/

int a[]={5,6,7,8};
// int *p=&a[0]; 一般简写为
int
 *p=a;
printf(
"p address %p \n",p);
printf(
"p value %i \n"*p);
//指针自加 p++  p=a[1]
p++;
printf(
"p++ value %i \n",*p);

// 指针的比较运算,比较的是两个指针的地址, 但只有一个数组内的指针比较才有意义。
//如果为true  输出 1, 如果为 false 输出0  ,c 语言中没有 boolean 类型
printf(" complete p %i \n", p+2>p);
printf(
" complete p %i \n", p+2<p);
//指针相减表示两个指针之间相差的元素个数, C语言也规定两个指针不能相加
printf(" p-1 value %i",*(p-1));

posted @ 2011-05-13 11:57 xsong 阅读(162) | 评论 (0)编辑 收藏

//使用指针访问结构体

struct unit{
char c;
int num;
};

 
struct unit u;
struct unit *p=&u;
//可使用 (*p).c=‘a'  通过指针访问结构体里的数据, c提供了 ->运算符 简化指针对结构体的访问 p->c='c'
(*p).c='a';
(
*p).num=2;
p
->c='c';
p
->num=1;

printf(
"p->c is %c \n",p->c);
printf(
"p->i is %i \n",p->num);

posted @ 2011-05-13 11:57 xsong 阅读(186) | 评论 (0)编辑 收藏

结构体
    *


struct Complex{ 
     
double x,y;
} z1;

//或者
struct Complex{
     
double x,y;
};
struct Complex z1;


//声明时初始化
struct Stu{
char name;
}s1
={'s'};

//先声明,后初始化
struct Stu{
     
char name;
};
struct Stu s1={s};

//结构体赋值 ,copy s1的内容给s2

struct Stu s2=s1;
s2.name
='m'

printf(
"s1.name %c",s1.name); // print s
printf("s2.name %c",s2.name); //print m

//结构体嵌套
struct dog{
char run;
};
struct cat{
char run;
};
struct animal{
struct dog dd;
struct cat cc;
};


 
//嵌套的结构体分别初始化
struct dog dd={'d'};
struct cat cc={'c'};
struct animal a1={dd ,cc};
printf(
"dog-dd run is %c \n",a1.dd.run);
printf(
"cat-cc run is %c",a1.cc.run);



posted @ 2011-05-13 11:55 xsong 阅读(191) | 评论 (0)编辑 收藏

声明一个字符串,其实也就是一个char的数组
char str[20] = "Hello, world";
printf("str is %s",str);
如果定义数组的大小 小于字符串字面值“Hello ,world"; 则编译器会发出警告信息。所以最好定义不定长度的数组
char str[ ]="hello, world";

posted @ 2011-05-13 11:55 xsong 阅读(146) | 评论 (0)编辑 收藏

deb http://mirrors.163.com/debian/ testing main non-free contrib
deb-src http://mirrors.163.com/debian/ testing main non-free contrib

deb http://mirrors.163.com/debian-security testing/updates main
deb-src http://mirrors.163.com/debian-security testing/updates main

posted @ 2011-05-13 11:52 xsong 阅读(2122) | 评论 (0)编辑 收藏

     摘要: java 证书公钥加密 生成xml 使用http post发送到servl et , servlet私钥解密 xml格式 1 :消息格式: XML 消息格式如下: <?xml version="1.0" encoding="UTF-8"> <Requ...  阅读全文

posted @ 2011-05-13 11:50 xsong 阅读(1677) | 评论 (0)编辑 收藏

1.OutputStream写入String

ByteArrayOutputStream baos 
= new ByteArrayOutputStream();  
//向OutPutStream中写入,如 message.writeTo(baos);  
String str = baos.toString();  

2.字符串转inputStream

String string;  
//  
InputStream is = new ByteArrayInputStream(string.getBytes());

3.InputStream转字符串

ByteArrayOutputStream baos 
= new ByteArrayOutputStream();  
int i;  
while ((i = is.read()) != -1) {  
    baos.write(i);  
}  
String str 
= baos.toString();  
System.out.println(str);  


4.String写入OutputStream

OutputStream os 
= System.out;  
os.write(string.getBytes());

posted @ 2011-05-13 11:48 xsong 阅读(4898) | 评论 (0)编辑 收藏

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import javax.crypto.*;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.IvParameterSpec;
import java.io.UnsupportedEncodingException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;

/**
 * User: fengxuesong
 * Date: 11-3-30
 * Time: 下午4:48
 * 使用 DES 加密解密
 
*/
public class DesTest {

    
static final byte[] IV = new byte[]{-29105540-94-98-113-100};
    
static final String priKey="11111111111";
    
static final String data="admin11";

    
public static void main(String args[]) throws Exception {

        
//加密
        String encrypt  = encodeDesWithBase64(priKey,data);
        
//输出加密的字符串
        System.out.println(encrypt );

        String decrypt 
=decodeDesWithBase64(priKey,encrypt );
        System.out.println(decrypt );
    }

    
private static String encodeDesWithBase64(String priKey,String data) throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException {
        DESKeySpec desKS 
= new DESKeySpec(priKey.getBytes());
        SecretKeyFactory skf 
= SecretKeyFactory.getInstance("DES");
        SecretKey sk 
= skf.generateSecret(desKS);
        Cipher cip 
= Cipher.getInstance("DES/CBC/PKCS5Padding");
        cip.init(Cipher.ENCRYPT_MODE, sk, 
new IvParameterSpec(IV));
        
byte bb [] =cip.doFinal(data.getBytes());
        
return new BASE64Encoder().encode(bb);
    }
    
private static String decodeDesWithBase64(String priKey,String data) throws Exception{
        DESKeySpec desKS 
= new DESKeySpec(priKey.getBytes());
        SecretKeyFactory skf 
= SecretKeyFactory.getInstance("DES");
        SecretKey sk 
= skf.generateSecret(desKS);
        Cipher cip 
= Cipher.getInstance("DES/CBC/PKCS5Padding");
        cip.init(Cipher.DECRYPT_MODE, sk, 
new IvParameterSpec(IV));
        
byte bb [] =cip.doFinal(new BASE64Decoder().decodeBuffer(data));
        
return new String(bb);
    }
}

posted @ 2011-05-13 11:46 xsong 阅读(258) | 评论 (0)编辑 收藏

Tomcat Server在启动的时候将构造一个ClassLoader树,以保证模块的类库是私有的
Tomcat Server的ClassLoader结构如下:

其中:
- Bootstrap - 载入JVM自带的类和$JAVA_HOME/jre/lib/ext/*.jar
- System - 载入$CLASSPATH/*.class
- Common - 载入$CATALINA_HOME/common/...,它们对TOMCAT和所有的WEB APP都可见
- Catalina - 载入$CATALINA_HOME/server/...,它们仅对TOMCAT可见,对所有的WEB APP都不可见
- Shared - 载入$CATALINA_HOME/shared/...,它们仅对所有WEB APP可见,对TOMCAT不可见(也不必见)
- WebApp? - 载入ContextBase?/WEB-INF/...,它们仅对该WEB APP可见

posted @ 2011-05-13 11:44 xsong 阅读(173) | 评论 (0)编辑 收藏

仅列出标题
共3页: 上一页 1 2 3 下一页