⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 toc.c

📁 This is code tutorial for image processing include:histogram,sketon....
💻 C
📖 第 1 页 / 共 2 页
字号:
  pad_string(...

  This function inserts spaces into the beginning 
  (left side) of a string.

  A. Declare variables.
  B. Fill a temporary string with num_blanks spaces.
  C. Concatenate input string onto temporary string.
  D. Copy temporary string back to input string.

*/

void pad_string(char string[], int num_blanks)
{
/* A. */
   int   count;
   char  temp[LENGTH];

/* B. */
   for(count = 0; count < num_blanks; count++)
      temp[count] = ' ';
   temp[count] = '\0';
/* C. */
   strcat(temp, string);
/* D. */
   strcpy(string, temp);

}  /* end of pad_string function */
/**************************************************/
/*PAGE make_new_page function

  make_new_page(...

  This function fills the remainder of a page with 
  blank lines and prints a header at the top of 
  the next page.

  A. Declare variables.
  B. Loop until the page runs out of lines.
  C. If you reach the end of a page, then
        D. Print FOOTER blank lines, jump to the 
           next page, and print a page header.

*/

void make_new_page(FILE *input_file, 
                   FILE *output_file,
                   char *name_of_input_file, 
                   char *time_string,
                   int *page_counter, 
                   int *line_counter)
{
/* A. */
   int  i, not_finished = 1;

/* B. */
   while(not_finished){

/* C. */
      if(*line_counter >= LPP - FOOT_SPACE){

/* D. */
         not_finished = 0;
         for(i=0; i<FOOTER; i++) 
            blank_line(output_file);
         *line_counter = 0;
         *page_counter = *page_counter + 1;
         blank_line(output_file);
         *line_counter = *line_counter + 1;
         write_3_line_header(output_file, 
                             name_of_input_file,
                             time_string, 
                             page_counter);
         *line_counter = *line_counter + 3;
         blank_line(output_file);
         *line_counter = *line_counter + 1;
      }  /* end of if line counter >= LPP - 10 */
      fputs("     \n", output_file);
      *line_counter = *line_counter + 1;
   }  /* end of while not_finished */
}  /* end of make_new_page function */
/**************************************************/
/*PAGE strip_title function

  strip_title(...

  This function takes an array (title) which has 
  the PAGE comment followed by a title and returns 
  an array (string) with only the title remaining.
  It strips out the PAGE comment and leaves the title.
  For example, 
     title = CPAGE This is a title
  the result,  
     string = This is a title

  A. Declare variables.
  B. Strip the first word out of the title array
        and put the result into the string array.
  C. Remove any special comment characters which may be
        at the end of the string array.

*/

void strip_title(char title[], char string[])
{
/* A. */
   int  i, n, second_word, space = ' ';
   char *first_space;

/* B. */
   first_space = strchr(title, space);
   second_word = first_space - title + 1;

   for(i=second_word; i<LENGTH; i++){
      string[i-second_word] = title[i];
      if(title[i] == '\0')
         i = 81;
   }  /* end of loop over i */

/* C. */
   i = strlen(string);
   i--;

   if(i > 0){
      n = 1;
      while(n){
         if(string[i] == '\n'  ||
            string[i] == '/'   ||
            string[i] == '*'){
           string[i] = '\0';
           i--;
         }  /* end of if string[i] */
         else
            n = 0;
      }  /* end of while n */
   }  /* end of if i > 0 */
}  /* end of strip_title function */
/**************************************************/
/*PAGE write_3_line_header function

  write_3_line_header(...

  This function writes a three line header to the 
  top of a new page.  The header contains the file 
  name, date, and page number.

  A. Declare variables.
  B. Fill strings with blanks.
  C. Fill strings with information and send to
        the output file.

*/

void write_3_line_header(FILE *file, 
                         char *file_name,
                         char *time_string, 
                         int *page_number)
{
/* A. */
   char b1[LENGTH], b2[LENGTH], 
        b3[LENGTH], string[LENGTH];
   int  i;

/* B. */
   for(i=0; i<LENGTH; i++){
      b1[i]     = ' ';
      b2[i]     = ' ';
      b3[i]     = ' ';
      string[i] = ' ';
   } /* end of loop over i */

   b1[LENGTH-15] = '\0';
   b2[LENGTH-15] = '\0';
   b3[LENGTH-15] = '\0';

/* C. */
   sprintf(string, "%s\n", file_name);
   strcat(b1, string);
   fputs(b1, file);

   sprintf(string, "%s\n", time_string);
   strcat(b2, string);
   fputs(b2, file);

   sprintf(string, "Page %d\n", *page_number);
   strcat(b3, string);
   fputs(b3, file);

}  /* end of write_3_line_header function */
/**************************************************/
/*PAGE blank_line function
 
  blank_line(...
  
  This function sends a blank line to a file.
*/

void blank_line(FILE *file)
{
   fputs("          \n", file);
} /* end of blank_line function */
/**************************************************/
/*PAGE contains_page_marker function

   contains_page_marker(...

   This function compares the input string char 
   array with the PAGE strings in the PAGES array 
   defined at the top of this program.  If the string 
   matches any of the PAGE strings in the PAGES array,
   it returns a 1, else it returns a 0.

*/

int contains_page_marker(char *string)
{
   int i      = 0, 
       result = 0;

   for(i=0; i<PAGE_TYPE && PAGES[i][0] != '\0'; i++){
      if( strncmp(PAGES[i], string, 5) == 0){
         result = 1;
         i      = PAGE_TYPE;
      }
   }

   return(result);
}  /* end of contains_page_marker function */
/**************************************************/
/*PAGE start_toc_file function

   start_toc_file(...

   This function sends the text that appears at the
   top of every table of contents page to the
   table of contents file.
*/

void start_toc_file(FILE *toc_file, 
                    char *name_of_input_file,
                    char time_string[],
                    char title_line[],
                    int  *toc_line_counter,
                    int  page_number)
{
   char a_string[LENGTH],
        stripped_title[LENGTH];

   blank_line(toc_file);
   *toc_line_counter = *toc_line_counter + 1;
   blank_line(toc_file);
   *toc_line_counter = *toc_line_counter + 1;
   blank_line(toc_file);
   *toc_line_counter = *toc_line_counter + 1;

   fputs(
"                               Table of Contents\n", 
      toc_file);
   *toc_line_counter = *toc_line_counter + 1;
   fputs(
"                                    for file\n", 
      toc_file);
   *toc_line_counter = *toc_line_counter + 1;

   sprintf(a_string,
      "                                    %s\n",
      name_of_input_file);
   fputs(a_string, toc_file);
   *toc_line_counter = *toc_line_counter + 1;
   blank_line(toc_file);
   *toc_line_counter = *toc_line_counter + 1;
   sprintf(a_string,
   "                                    %s\n",
           time_string);
   fputs(a_string, toc_file);
   *toc_line_counter = *toc_line_counter + 1;
   blank_line(toc_file);
   *toc_line_counter = *toc_line_counter + 1;
   fputs("        Page - Contents\n", toc_file);
   *toc_line_counter = *toc_line_counter + 1;

   strip_title(title_line, stripped_title);
   sprintf(a_string, "        %4d - %s\n",
           page_number, stripped_title);
   fputs(a_string, toc_file);
   *toc_line_counter = *toc_line_counter + 1;

}  /* end of start_toc_file function */
/**************************************************/
/*PAGE write_title_to_toc_file function

   write_title_to_toc_file(...

   This function writes one line of table of
   contents information to the table of contents
   file.

*/

void write_title_to_toc_file(FILE *toc_file, 
                    char *name_of_input_file,
                    char time_string[],
                    char title_line[],
                    int  *toc_line_counter,
                    int  page_number)
{
   char a_string[LENGTH],
        stripped_title[LENGTH];
   int  i;

   strip_title(title_line, stripped_title);
   sprintf(a_string, "        %4d - %s\n",
           page_number, stripped_title);
   fputs(a_string, toc_file);
   *toc_line_counter = *toc_line_counter + 1;

   if(*toc_line_counter >= LPP-10){
      *toc_line_counter = 0;
      for(i=0; i<FOOTER; i++) blank_line(toc_file);
      start_toc_file(toc_file, 
                     name_of_input_file,
                     time_string,
                     title_line,
                     toc_line_counter,
                     page_number);
   }

}  /* end of write_title_to_toc_file function */
/**************************************************/
/*PAGE end_toc_page function

   end_toc_page(...
   
   This function finished off the bottom of the
   table of contents page.
*/

void end_toc_page(FILE *toc_file, 
                  int  *toc_line_counter)
{
   int i;

   for(i=*toc_line_counter; i<LPP; i++)
      blank_line(toc_file);
}  /* end of end_toc_page function */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -