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

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

          int main(void) {
              
          // 使用 malloc 分配內(nèi)存, 使用free釋放內(nèi)存,并設置為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訪問內(nèi)存
              free(p->msg);
              free(p);
              
          //如果 free(p)  兩次, 則會引發(fā)系統(tǒng)錯誤,
              p=NULL;

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

              
          return EXIT_SUCCESS;
          }

          posted @ 2011-05-16 13:42 xsong 閱讀(173) | 評論 (0)編輯 收藏

          /*數(shù)組和指針
          * 在函數(shù)原型中,如果參數(shù)是數(shù)組,則等價于參數(shù)是指針的形式,例如:
          void func(int a[10])
          {

          }
          等價于:

          void func(int *a)
          {

          }
          第一種形式方括號中的數(shù)字可以不寫,仍然是等價的:

          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);

          // 指針的比較運算,比較的是兩個指針的地址, 但只有一個數(shù)組內(nèi)的指針比較才有意義。
          //如果為true  輸出 1, 如果為 false 輸出0  ,c 語言中沒有 boolean 類型
          printf(" complete p %i \n", p+2>p);
          printf(
          " complete p %i \n", p+2<p);
          //指針相減表示兩個指針之間相差的元素個數(shù), C語言也規(guī)定兩個指針不能相加
          printf(" p-1 value %i",*(p-1));

          posted @ 2011-05-13 11:57 xsong 閱讀(177) | 評論 (0)編輯 收藏

          //使用指針訪問結(jié)構(gòu)體

          struct unit{
          char c;
          int num;
          };

           
          struct unit u;
          struct unit *p=&u;
          //可使用 (*p).c=‘a'  通過指針訪問結(jié)構(gòu)體里的數(shù)據(jù), c提供了 ->運算符 簡化指針對結(jié)構(gòu)體的訪問 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 閱讀(195) | 評論 (0)編輯 收藏

          結(jié)構(gòu)體
              *


          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};

          //結(jié)構(gòu)體賦值 ,copy s1的內(nèi)容給s2

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

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

          //結(jié)構(gòu)體嵌套
          struct dog{
          char run;
          };
          struct cat{
          char run;
          };
          struct animal{
          struct dog dd;
          struct cat cc;
          };


           
          //嵌套的結(jié)構(gòu)體分別初始化
          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 閱讀(203) | 評論 (0)編輯 收藏

          聲明一個字符串,其實也就是一個char的數(shù)組
          char str[20] = "Hello, world";
          printf("str is %s",str);
          如果定義數(shù)組的大小 小于字符串字面值“Hello ,world"; 則編譯器會發(fā)出警告信息。所以最好定義不定長度的數(shù)組
          char str[ ]="hello, world";

          posted @ 2011-05-13 11:55 xsong 閱讀(172) | 評論 (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 閱讀(2141) | 評論 (0)編輯 收藏

               摘要: java 證書公鑰加密 生成xml 使用http post發(fā)送到servl et , servlet私鑰解密 xml格式 1 :消息格式: XML 消息格式如下: <?xml version="1.0" encoding="UTF-8"> <Requ...  閱讀全文

          posted @ 2011-05-13 11:50 xsong 閱讀(1694) | 評論 (0)編輯 收藏

          1.OutputStream寫入String

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

          2.字符串轉(zhuǎn)inputStream

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

          3.InputStream轉(zhuǎn)字符串

          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 閱讀(4919) | 評論 (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 閱讀(269) | 評論 (0)編輯 收藏

          Tomcat Server在啟動的時候?qū)?gòu)造一個ClassLoader樹,以保證模塊的類庫是私有的
          Tomcat Server的ClassLoader結(jié)構(gòu)如下:

          其中:
          - 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 閱讀(184) | 評論 (0)編輯 收藏

          僅列出標題
          共3頁: 上一頁 1 2 3 下一頁 
          主站蜘蛛池模板: 云梦县| 凉山| 滕州市| 商洛市| 翁牛特旗| 天台县| 永年县| 灵川县| 刚察县| 拉萨市| 贺兰县| 巴林左旗| 博罗县| 尉氏县| 明溪县| 昌图县| 淮安市| 景宁| 宝丰县| 万载县| 兴安盟| 合阳县| 贞丰县| 阳信县| 西宁市| 台州市| 尼木县| 普兰店市| 广宁县| 桦南县| 江津市| 肇州县| 赤水市| 布尔津县| 新干县| 瓮安县| 花莲县| 赤城县| 巴彦淖尔市| 洛南县| 彭山县|