例如:
C程序:
#include <stdio.h>
#include<iostream>
#include <math.h>
int main()
{
    int m,k,i,j,n,h=O,num[500];
    scanf("%d%d",&m,&n);
    for(j=m;j<=n;j++){
          k =j/2;
          for(i=2;i<=k;i++){
              if(j%1==0)
                      break;
          }
          if(i>=k+1){
              num[h] =j;
              h++;}
    }
    for(i=O;i<h;i++)
      printf("%d  ",num[i]);
}
要求转化成的XML格式:
<code>
<function name="main"  returntype="int" number="0" body=" {int m,k,ij,n,h=0,
num[500];for(j=m;;j<=n;j= j+1){k=j/2;for(i=2;i<=k;i=i+l){if(j%i==0){break;}}if(i>=k
+l ) {num[h] =j;h=h+l;}} for(i=O;i<h;i=i+1){;}}”>
<variables body="int m,k,i,j,n,h=O,num[500];">
<var type="int" name="m" value="" big=""></var>
<var type="int" name="k" value="" big=""></var>
<var type="int" name="i" value="" big=""></var>
<var type="int" name='j”value="" big=" "></var>
<var type="int" name="n" value="" big=" "></var>
<var type="int" name="h" value="0" big=""></var>
<var type="int" name="num" value="" big="500"></var>
</variables>
<other>h=0;</other>
<other>j=m;</other>
<for condition="j<=n" body="{k= j/2;for(i=2;i<=k;i=i+l){if(j%i==0){break;}}if(i>=
k+l ) {num[h]勺;h=h+l;}}”>
<other>k= j/2;</other>
<other>i=2;</other>
<for condition="i<=k" body=" {if(j%i==0) {break; }}”〕
<if condition='j%i==0" body=" {break;}”>
<other>break;</other>
</if>
<other>i=i+l ;</other>
</for>
<if condition="i>=k+1”body="{num[h] =j;h=h+i;}}}>
<other>num[h] =j;</other>
<other>h=h+l ;</other>
</i介
<other>j=j+l ;</other>
</for>
<other>i=0;</other>
<for condition="i<h" body="{;}”>
<other>i=i+l;</other>
</for>
</function>
</code>
CXML存储转化

解决方案 »

  1.   

    非常感谢您的回复,但是TinyXML我不会用,搜了下,好像是读取XML文件的,可以用来将C转化为XML存储吗
      

  2.   

    http://blog.csdn.net/chexlong/article/details/6452538
      

  3.   

    //创建XML配置文件
    bool createXmlFile(string& sXFileName)
    {
        TiXmlDocument* pXmlDoc = new TiXmlDocument;
        if (pXmlDoc == NULL)
        {
            return false;
        }    TiXmlElement* pRootElem = new TiXmlElement("SecondScene");
        if (pRootElem == NULL)
        {
            return false;
        }
        pXmlDoc->LinkEndChild(pRootElem);    TiXmlElement* pEnvElem = new TiXmlElement("Environment");
        if (pEnvElem == NULL)
        {
            return false;
        }
        pRootElem->LinkEndChild(pEnvElem);    TiXmlElement* pObjectsElem = new TiXmlElement("Objects");
        if (pObjectsElem == NULL)
        {
            return false;
        }
        pRootElem->LinkEndChild(pObjectsElem);    TiXmlElement* pObjElem = new TiXmlElement("Object");
        if (pObjElem == NULL)
        {
            return false;
        }
        pObjectsElem->LinkEndChild(pObjElem);
        pObjElem->SetAttribute("Name", "cow.osg");    pXmlDoc->SaveFile(sXFileName);    return true;}