M
moonhkt
Hi All
I am testing how to checking control-L in text file.
abc.txt file
1 Line 1
2 ^L line 2 with control-L at 3
^L
some character before contro-l ^L
5
~
Output
openfile abc
Input file abc.txt
B 1 1 Line 1
B 2 2
line 2 with control-L at 3
A 3
Page ended with control-L
B 4 some character before contro-l
Page ended with control-L
B 5 5
How to replace ^L with varaible ? for line if (!strncmp(line,"^L",1))
{ /* 12 form feed */ ?
and int ff = (int) '^L'; how to using \f replace ^L ?
/* gcc -o openfile openfile.c
check control-L location
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#define PAGELENGTH 512
#define LINELENGTH 512
#define NAMELENGTH 64
int idx;
int ftype;
char *page[PAGELENGTH];
char line[LINELENGTH];
char line2[LINELENGTH];
char *ifile;
char *ofile;
FILE *ifp;
FILE *ofp;
char key[32];
main(int argc, char *argv[])
{
int result;
int len ;
int ff = (int) '^L';
ifile = malloc (NAMELENGTH);
result = sprintf(ifile, "%s%s", argv[1], ".txt");
printf("Input file %s\n", ifile);
ifp = fopen (ifile, "r");
if (ifp == NULL) { printf ("Failed to open input file.
\n"); exit (1); }
while (fgets(line, LINELENGTH, ifp) != NULL) {
idx++;
if (!strncmp(line,"^L",1)) { /* 12 form feed */
printf("A %d %s",idx,line);
} else {
printf("B %d %s",idx,line);
}
len = strlen(line);
if (line[len-2] == ff ) {
printf ("Page ended with control-L\n");
}
}
}
I am testing how to checking control-L in text file.
abc.txt file
1 Line 1
2 ^L line 2 with control-L at 3
^L
some character before contro-l ^L
5
~
Output
openfile abc
Input file abc.txt
B 1 1 Line 1
B 2 2
line 2 with control-L at 3
A 3
Page ended with control-L
B 4 some character before contro-l
Page ended with control-L
B 5 5
How to replace ^L with varaible ? for line if (!strncmp(line,"^L",1))
{ /* 12 form feed */ ?
and int ff = (int) '^L'; how to using \f replace ^L ?
/* gcc -o openfile openfile.c
check control-L location
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#define PAGELENGTH 512
#define LINELENGTH 512
#define NAMELENGTH 64
int idx;
int ftype;
char *page[PAGELENGTH];
char line[LINELENGTH];
char line2[LINELENGTH];
char *ifile;
char *ofile;
FILE *ifp;
FILE *ofp;
char key[32];
main(int argc, char *argv[])
{
int result;
int len ;
int ff = (int) '^L';
ifile = malloc (NAMELENGTH);
result = sprintf(ifile, "%s%s", argv[1], ".txt");
printf("Input file %s\n", ifile);
ifp = fopen (ifile, "r");
if (ifp == NULL) { printf ("Failed to open input file.
\n"); exit (1); }
while (fgets(line, LINELENGTH, ifp) != NULL) {
idx++;
if (!strncmp(line,"^L",1)) { /* 12 form feed */
printf("A %d %s",idx,line);
} else {
printf("B %d %s",idx,line);
}
len = strlen(line);
if (line[len-2] == ff ) {
printf ("Page ended with control-L\n");
}
}
}