A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2FStructure%2FStructure_Serialization</id>
		<title>C/Structure/Structure Serialization - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2FStructure%2FStructure_Serialization"/>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C/Structure/Structure_Serialization&amp;action=history"/>
		<updated>2026-04-08T23:01:00Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://cppe.ru/index.php?title=C/Structure/Structure_Serialization&amp;diff=126&amp;oldid=prev</id>
		<title> в 14:20, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C/Structure/Structure_Serialization&amp;diff=126&amp;oldid=prev"/>
				<updated>2010-05-25T14:20:56Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:20, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://cppe.ru/index.php?title=C/Structure/Structure_Serialization&amp;diff=127&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C/Structure/Structure_Serialization&amp;diff=127&amp;oldid=prev"/>
				<updated>2010-05-25T10:22:14Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==scan a file and print out a list of words in ASCII order==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Practical C Programming, Third Edition&lt;br /&gt;
By Steve Oualline&lt;br /&gt;
Third Edition August 1997 &lt;br /&gt;
ISBN: 1-56592-306-5&lt;br /&gt;
Publisher: O&amp;quot;Reilly&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ctype.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;    &lt;br /&gt;
struct node {&lt;br /&gt;
    struct node    *left;       /* tree to the left */&lt;br /&gt;
    struct node    *right;      /* tree to the right */&lt;br /&gt;
    char           *word;       /* word for this tree */&lt;br /&gt;
};&lt;br /&gt;
/* the top of the tree */&lt;br /&gt;
static struct node *root = NULL;&lt;br /&gt;
/*&lt;br /&gt;
 * memory_error -- write error and die                  *&lt;br /&gt;
 */&lt;br /&gt;
void memory_error(void)&lt;br /&gt;
{&lt;br /&gt;
    fprintf(stderr, &amp;quot;Error:Out of memory\n&amp;quot;);&lt;br /&gt;
    exit(8);&lt;br /&gt;
}&lt;br /&gt;
/*&lt;br /&gt;
 * save_string -- save a string on the heap             *&lt;br /&gt;
 *                                                      *&lt;br /&gt;
 * Parameters                                           *&lt;br /&gt;
 *      string -- string to save                        *&lt;br /&gt;
 *                                                      *&lt;br /&gt;
 * Returns                                              *&lt;br /&gt;
 *      pointer to malloc-ed section of memory with     *&lt;br /&gt;
 *      the string copied into it.                      *&lt;br /&gt;
 */&lt;br /&gt;
char *save_string(char *string)&lt;br /&gt;
{&lt;br /&gt;
    char *new_string;   /* where we are going to put string */&lt;br /&gt;
    new_string = malloc((unsigned) (strlen(string) + 1));&lt;br /&gt;
    if (new_string == NULL)&lt;br /&gt;
        memory_error();&lt;br /&gt;
    strcpy(new_string, string);&lt;br /&gt;
    return (new_string);&lt;br /&gt;
}&lt;br /&gt;
/*&lt;br /&gt;
 * enter -- enter a word into the tree                  *&lt;br /&gt;
 *                                                      *&lt;br /&gt;
 * Parameters                                           *&lt;br /&gt;
 *      node -- current node we are looking at          *&lt;br /&gt;
 *      word -- word to enter                           *&lt;br /&gt;
 */&lt;br /&gt;
void enter(struct node **node, char *word)&lt;br /&gt;
{&lt;br /&gt;
    int  result;        /* result of strcmp */&lt;br /&gt;
    char *save_string(char *);  /* save a string on the heap */&lt;br /&gt;
    /* &lt;br /&gt;
     * If the current node is null, we have reached the bottom&lt;br /&gt;
     * of the tree and must create a new node.&lt;br /&gt;
     */&lt;br /&gt;
    if ((*node) == NULL) {&lt;br /&gt;
  /* Allocate memory for a new node */&lt;br /&gt;
        (*node) = malloc(sizeof(struct node));&lt;br /&gt;
        if ((*node) == NULL)&lt;br /&gt;
            memory_error();&lt;br /&gt;
  /* Initialize the new node */&lt;br /&gt;
        (*node)-&amp;gt;left = NULL;&lt;br /&gt;
        (*node)-&amp;gt;right = NULL;&lt;br /&gt;
        (*node)-&amp;gt;word = save_string(word);&lt;br /&gt;
  return;&lt;br /&gt;
    }&lt;br /&gt;
    /* Check to see where the word goes */&lt;br /&gt;
    result = strcmp((*node)-&amp;gt;word, word);&lt;br /&gt;
    /* The current node already contains the word, no entry necessary */&lt;br /&gt;
    if (result == 0)&lt;br /&gt;
        return;&lt;br /&gt;
    /* The word must be entered in the left or right sub-tree */&lt;br /&gt;
    if (result &amp;lt; 0)&lt;br /&gt;
        enter(&amp;amp;(*node)-&amp;gt;right, word);&lt;br /&gt;
    else&lt;br /&gt;
        enter(&amp;amp;(*node)-&amp;gt;left, word);&lt;br /&gt;
}&lt;br /&gt;
/*&lt;br /&gt;
 * scan -- scan the file for words                      *&lt;br /&gt;
 *                                                      *&lt;br /&gt;
 * Parameters                                           *&lt;br /&gt;
 *      name -- name of the file to scan                *&lt;br /&gt;
 */&lt;br /&gt;
void scan(char *name)&lt;br /&gt;
{&lt;br /&gt;
    char word[100];     /* word we are working on */&lt;br /&gt;
    int  index;         /* index into the word */&lt;br /&gt;
    int  ch;            /* current character */&lt;br /&gt;
    FILE *in_file;      /* input file */&lt;br /&gt;
    in_file = fopen(name, &amp;quot;r&amp;quot;);&lt;br /&gt;
    if (in_file == NULL) {&lt;br /&gt;
        fprintf(stderr, &amp;quot;Error:Unable to open %s\n&amp;quot;, name);&lt;br /&gt;
        exit(8);&lt;br /&gt;
    }&lt;br /&gt;
    while (1) {&lt;br /&gt;
        /* scan past the whitespace */&lt;br /&gt;
        while (1) {&lt;br /&gt;
            ch = fgetc(in_file);&lt;br /&gt;
            if (isalpha(ch) || (ch == EOF))&lt;br /&gt;
                break;&lt;br /&gt;
        }&lt;br /&gt;
        if (ch == EOF)&lt;br /&gt;
            break;&lt;br /&gt;
        word[0] = ch;&lt;br /&gt;
        for (index = 1; index &amp;lt; sizeof(word); ++index) {&lt;br /&gt;
            ch = fgetc(in_file);&lt;br /&gt;
            if (!isalpha(ch))&lt;br /&gt;
                break;&lt;br /&gt;
            word[index] = ch;&lt;br /&gt;
        }&lt;br /&gt;
        /* put a null on the end */&lt;br /&gt;
        word[index] = &amp;quot;\0&amp;quot;;&lt;br /&gt;
        enter(&amp;amp;root, word);&lt;br /&gt;
    }&lt;br /&gt;
    fclose(in_file);&lt;br /&gt;
}&lt;br /&gt;
/*&lt;br /&gt;
 * print_tree -- print out the words in a tree          *&lt;br /&gt;
 *                                                      *&lt;br /&gt;
 * Parameters                                           *&lt;br /&gt;
 *      top -- the root of the tree to print            *&lt;br /&gt;
 */&lt;br /&gt;
void print_tree(struct node *top)&lt;br /&gt;
{&lt;br /&gt;
    if (top == NULL)&lt;br /&gt;
        return;                 /* short tree */&lt;br /&gt;
    print_tree(top-&amp;gt;left);&lt;br /&gt;
    printf(&amp;quot;%s\n&amp;quot;, top-&amp;gt;word);&lt;br /&gt;
    print_tree(top-&amp;gt;right);&lt;br /&gt;
}&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    if (argc != 2) {&lt;br /&gt;
        fprintf(stderr, &amp;quot;Error:Wrong number of parameters\n&amp;quot;);&lt;br /&gt;
        fprintf(stderr, &amp;quot;      on the command line\n&amp;quot;);&lt;br /&gt;
        fprintf(stderr, &amp;quot;Usage is:\n&amp;quot;);&lt;br /&gt;
        fprintf(stderr, &amp;quot;    words &amp;quot;file&amp;quot;\n&amp;quot;);&lt;br /&gt;
        exit(8);&lt;br /&gt;
    }&lt;br /&gt;
    scan(argv[1]);&lt;br /&gt;
    print_tree(root);&lt;br /&gt;
    return (0);&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Write structure into file==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C &amp;amp; Data Structures&lt;br /&gt;
Published in Feb 2004 by CHARLES RIVER MEDIA&lt;br /&gt;
Author: P. S. Deshpande, O. G. Kakde&lt;br /&gt;
SKU: 1584503386&lt;br /&gt;
ISBN: 1584503386&lt;br /&gt;
*/ &lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#define MAX 50&lt;br /&gt;
&lt;br /&gt;
typedef struct {&lt;br /&gt;
    char  name[10];&lt;br /&gt;
    int key;&lt;br /&gt;
} file_record;&lt;br /&gt;
/* this function adds the relatiuve addres to the index for a key */&lt;br /&gt;
void create_index(long index[], int key, long rel_add ) {&lt;br /&gt;
    index[key] = rel_add;&lt;br /&gt;
}&lt;br /&gt;
/* this function writes a record to the file */&lt;br /&gt;
void write_rec(FILE *fp, file_record rec) {&lt;br /&gt;
   fwrite(&amp;amp;rec,sizeof(rec),1,fp);&lt;br /&gt;
}&lt;br /&gt;
void main() {&lt;br /&gt;
    long rel_add;&lt;br /&gt;
    int key;&lt;br /&gt;
    file_record frec;&lt;br /&gt;
    long index[MAX];/* an index list*/&lt;br /&gt;
    int n,i;&lt;br /&gt;
    FILE *recfile=NULL,*ifile=NULL;&lt;br /&gt;
    /* this initializes the index list to all ? */&lt;br /&gt;
    for(i=0; i&amp;lt; MAX; i++)&lt;br /&gt;
        index[i]= (-1);&lt;br /&gt;
    recfile=fopen(&amp;quot;mfile&amp;quot;,&amp;quot;w&amp;quot;);&lt;br /&gt;
    if(recfile == NULL) {&lt;br /&gt;
        printf(&amp;quot;Error in openeing file mfile\n&amp;quot;);&lt;br /&gt;
        exit(0);&lt;br /&gt;
    }&lt;br /&gt;
    rel_add = 0 ;&lt;br /&gt;
    do {&lt;br /&gt;
        printf(&amp;quot; Enter the data vlue and the key of the record to be added to file mfile\n&amp;quot;);&lt;br /&gt;
        scanf(&amp;quot;%s %d&amp;quot;,frec.name,&amp;amp;frec.key);&lt;br /&gt;
        while(index[frec.key] != (-1)) {&lt;br /&gt;
            printf(&amp;quot; A record with this key value already exist in a file enter record key value\n&amp;quot;);&lt;br /&gt;
            scanf(&amp;quot;%s %d&amp;quot;,frec.name,&amp;amp;frec.key);&lt;br /&gt;
        }&lt;br /&gt;
        create_index(index,frec.key,rel_add);&lt;br /&gt;
         write_rec(recfile,frec);&lt;br /&gt;
        rel_add =  ftell(recfile); &lt;br /&gt;
        /* this sets the relative address for the next record to be &lt;br /&gt;
      the value of current file position pointer in bytes from &lt;br /&gt;
      the beginning of the file */&lt;br /&gt;
         printf(&amp;quot;Enter 1 to continue adding records to the file\n&amp;quot;);&lt;br /&gt;
         scanf(&amp;quot;%d&amp;quot;,&amp;amp;n);&lt;br /&gt;
    }while(n == 1);&lt;br /&gt;
   &lt;br /&gt;
    ifile=fopen(&amp;quot;index_file&amp;quot;,&amp;quot;w&amp;quot;);&lt;br /&gt;
         &lt;br /&gt;
    if(ifile == NULL) {&lt;br /&gt;
       printf(&amp;quot;Error in openeing file index_file\n&amp;quot;);&lt;br /&gt;
         exit(0);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    fwrite(index,sizeof(index),1,ifile);/*writes the complete index into the index_file */&lt;br /&gt;
    fclose(recfile);&lt;br /&gt;
    fclose(ifile);&lt;br /&gt;
    printf(&amp;quot;Enter 1 if you want to retrieve a record\n&amp;quot;);&lt;br /&gt;
    scanf(&amp;quot;%d&amp;quot;,&amp;amp;n);&lt;br /&gt;
    &lt;br /&gt;
    if( n == 1) {&lt;br /&gt;
       ifile=fopen(&amp;quot;index_file&amp;quot;,&amp;quot;r&amp;quot;);&lt;br /&gt;
       if(ifile == NULL) {&lt;br /&gt;
           printf(&amp;quot;Error in openeing file index_file\n&amp;quot;);&lt;br /&gt;
           exit(0);&lt;br /&gt;
       }&lt;br /&gt;
       fread(index,sizeof(index),1,ifile);&lt;br /&gt;
       &lt;br /&gt;
       /* reads the complete index into the index list from the index_file*/&lt;br /&gt;
       fclose(ifile);&lt;br /&gt;
       recfile=fopen(&amp;quot;mfile&amp;quot;,&amp;quot;r&amp;quot;);&lt;br /&gt;
       &lt;br /&gt;
       if(recfile == NULL) {&lt;br /&gt;
           printf(&amp;quot;Error in openeing file mfile\n&amp;quot;);&lt;br /&gt;
           exit(0);&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
    printf(&amp;quot;THE CONTENTS OF FILE IS \n&amp;quot;);&lt;br /&gt;
    &lt;br /&gt;
    while( (fread(&amp;amp;frec,sizeof(frec),1,recfile)) != 0)&lt;br /&gt;
         printf(&amp;quot;%s %d\n&amp;quot;,frec.name,frec.key);&lt;br /&gt;
    &lt;br /&gt;
    do {&lt;br /&gt;
        printf(&amp;quot;Enter the key of the record to be retrieved\n&amp;quot;);&lt;br /&gt;
        scanf(&amp;quot;%d&amp;quot;,&amp;amp;key);&lt;br /&gt;
        rel_add = index[key]; /*gets the relative address of the record from index list */&lt;br /&gt;
        if( (fseek(recfile,rel_add,SEEK_SET))!= 0) {&lt;br /&gt;
             printf(&amp;quot;Error\n&amp;quot;);&lt;br /&gt;
             exit(0);&lt;br /&gt;
        }&lt;br /&gt;
        fread(&amp;amp;frec,sizeof(frec),1,recfile);&lt;br /&gt;
        printf(&amp;quot;The data value of the retrieved record is %s\n&amp;quot;,frec.name);&lt;br /&gt;
        printf(&amp;quot;Enter 1 if you want to retrieve a record\n&amp;quot;);&lt;br /&gt;
        scanf(&amp;quot;%d&amp;quot;,&amp;amp;n);&lt;br /&gt;
    } while(n == 1);&lt;br /&gt;
    &lt;br /&gt;
    fclose(recfile);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>