📄 dummy.c
字号:
{
/* A. */
char string[MAX_STRING];
int not_finished = 1;
/* B. */
while(not_finished){
/* C. */
if(*line_counter >= LPP - 10){
/* D. */
not_finished = 0;
blank_line(output_file);
blank_line(output_file);
blank_line(output_file);
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(char title[], char string[])
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 6 characters 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.
*/
strip_title(char title[], char string[])
{
/* A. */
int i, n;
/* B. */
for(i=6; i<80; i++){
string[i-6] = 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(FILE *file, char *file_name,
char *time_string, int *page_number)
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.
*/
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(FILE *file)
*
* This function sends a blank line to a file.
*
* A. Send a string of blanks to a file.
*
*/
blank_line(FILE *file)
{
fputs(" \n", file);
} /* end of blank_line function */
/*PAGE write_table_of_contents function
write_table_of_contents(char *file_name,
char *input_file_name,
char titles[TITLES][LENGTH],
int titles_pages[TITLES],
char *time_string)
This function writes the table of contents information to a
file. The table of contents information text is in the
char array titles and the page numbers are in the int array
titles_pages.
A. Declare variables.
B. Open the table of contents file.
C. Write the table of contents title to the file.
D. Loop through the table of contents and write
each entry to the file.
E. Fill the remainder of the table of contents page with
blank lines.
F. Close the file.
*/
write_table_of_contents(char *file_name,
char *input_file_name,
char titles[TITLES][LENGTH],
int titles_pages[TITLES],
char *time_string)
{
/* A. */
char string[LENGTH], string2[LENGTH];
FILE *file;
int i, line_counter = 0;
printf("\nWTOC> start");
/* B. */
if((file = fopen(file_name, "wt")) == NULL){
printf("\ntoc: Error opening table of contents file\n");
exit(1);
} /* end of if */
printf(".");
/* C. */
blank_line(file);
line_counter++;
blank_line(file);
line_counter++;
blank_line(file);
line_counter++;
fputs(" Table of Contents\n", file);
line_counter++;
fputs(" for file\n", file);
line_counter++;
sprintf(string," %s\n",
input_file_name);
fputs(string, file);
line_counter++;
blank_line(file);
line_counter++;
sprintf(string," %s\n",
time_string);
fputs(string, file);
line_counter++;
blank_line(file);
line_counter++;
fputs(" Page - Contents\n", file);
line_counter++;
printf(".");
/* D. */
for(i=0; i<TITLES; i++){
if(titles[i][0] != '\0'){
strip_title(titles[i], string2);
sprintf(string, " %4d - %s\n",
titles_pages[i], string2);
fputs(string, file);
line_counter++;
} /* end if titles */
} /* end loop over i */
printf(".");
/* E. */
for(i=line_counter; i<LPP-4; i++)
blank_line(file);
printf(".");
/* F. */
fclose(file);
printf(".");
printf("\nWTOC> the end");
} /* end of write_table_of_contents function */
/*PAGE replace_slash function
replace_slash(char string[])
This function takes a string and replaces each
slash character with a back slash character.
*/
replace_slash(char string[])
{
int slash = 47,
back_slash = 92,
i,
j;
j = strlen(string);
for(i=0; i<j; i++){
if(string[i] == slash) string[i] = back_slash;
}
} /* end of replace_slash function */
/*PAGE get_unique_file_name function
get_unique_file_name(char *file_name)
This function creates a unique file name and
places it in the character string parameter.
Loop until you have found the unique name.
Use the random number generator and convert this to
a string.
See if a file exists having that name by trying to
open it.
*/
get_unique_file_name(char *file_name)
{
FILE *a_file;
int still_looking = 1;
while(still_looking){
sprintf(file_name, "%d", rand());
if((a_file = fopen(file_name, "rt")) == NULL)
still_looking = 0;
else
fclose(a_file);
} /* end of while still_looking */
} /* end of get_unique_file_name function */
/*PAGE new_page_marker function
new_page_marker(char *string)
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.
*/
new_page_marker(char *string)
{
int i = 0,
not_finished = 1,
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;
}
}
/***************
while(not_finished){
if( strncmp(PAGES[i], string, 5) == 0){
not_finished = 0;
result = 1;
}
else{
i++;
if(i >= PAGE_TYPE) not_finished = 0;
if(PAGES[i][0] == '\0') not_finished = 0;
}
} **********/ /* ends of while not_finished */
return(result);
} /* end of new_page_marker function */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -