本文整理汇总了C++中writelines函数的典型用法代码示例。如果您正苦于以下问题:C++ writelines函数的具体用法?C++ writelines怎么用?C++ writelines使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了writelines函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
int ret = 0;
int nlines = 0; /* number of input lines read */
int n = N;
printf("\n This program prints the last n lines from the input");
printf("\n\t nis 10 by default but we can change it by running the program with %s -n new_n_value\n", argv[0]);
if( (nlines = readlines(lineptr, MAXLINES)) > 0)
{
printf("\n");
if (argc == 1)
{
///printing the last 10 lines from the input
writelines(lineptr, nlines, n);
}
else if (argc == 3)
{
/// printing the last n lines from the input
writelines(lineptr, nlines, atoi(argv[2]));
}
else
printf("erorr for command line arguments");
}
return ret;
}
示例2: main
int main(int argc, char *argv[])
{
int ret = 0;
int nlines = 0; /* number of input lines read */
printf("\ntesting atoi %d", atoi("123"));
printf("\ntesting atoi %d", atoi("23"));
printf("\nThis program alphabetically sorts the input lines\nGive me some input\n");
if ((nlines = readlines(lineptr, MAXLINES)) >= 0)
{
printf("\n\t The lines in unsorted order are:\n");
writelines(lineptr, nlines);
if (argc == 1)
{
qsort(lineptr, nlines, sizeof(char *), cmpstringp);
printf("\n\t The lines sorted alphabetically in growing order are:\n");
writelines(lineptr, nlines);
}
else if (argc == 2)
{
if(!strcmp(argv[1], "-r"))
{
qsort(lineptr, nlines, sizeof(char *), cmpstringp_inv);
printf("\n\t The lines sorted alphabetically in reversed order are:\n");
writelines(lineptr, nlines);
}
if(!strcmp(argv[1], "-n"))
{
qsort(lineptr, nlines, sizeof(char *), numcmp);
printf("\n\t The lines sorted in num order are:\n");
writelines(lineptr, nlines);
}
}
else if (argc == 3)
{
if( (!strcmp(argv[1], "-r") && (!strcmp(argv[2], "-n"))) ||
((!strcmp(argv[1], "-n")) && (!strcmp(argv[2], "-r"))) )
qsort(lineptr, nlines, sizeof(char *), numcmp_inv);
printf("\n\t The lines sorted in reversed num order are:\n");
writelines(lineptr, nlines);
}
else
{
printf("\n error: wrong comand line parameters \n");
return ret + 1;
}
return ret;
}
else
{
printf("error: input too big to sort\n");
return ret + 1;
}
return ret;
}
示例3: main
int main(void)
{
int nlines; /* number of input lines read */
if ((nlines = readlines(lineptr, MAXLINES)) >= 0) {
writelines(lineptr, nlines);
quicksort(lineptr, 0, nlines -1);
writelines(lineptr, nlines);
return 0;
} else {
printf("error: input too big to sort\n");
return -1;
}
}
示例4: main
main(int argc, char *argv[])
{
int nlines; /* number of read lines */
int ignorecase, reverse, numeric; /* 1, if numerical comparison */
ignorecase = reverse = numeric = 0;
char c;
while (--argc > 0 && (*++argv)[0] == '-')
while (c = *++argv[0]) {
switch (c) {
case 'n':
numeric = 1;
break;
case 'r':
reverse = 1;
break;
case 'i':
ignorecase = 1;
break;
case 'h':
printf("Usage: "PROG" [-nird] \"STDIN\"\n");
return 0;
break;
default:
printf(PROG": illegal option %c\n", c);
argc = 0;
return 1;
break;
}
if (c == '\0')
break;
}
if ((nlines = readlines(lineptr, MAXLINES)) >= 0) {
printf("\nBefore sort:\n");
writelines(lineptr, nlines);
int (*pf) (const char *, const char *) = ignorecase ? _strcasecmp : _strcmp;
qsort((void **) lineptr, 0, nlines - 1,
(int (*)(void *, void *))(numeric ? numcmp : pf), reverse);
printf("\nAfter sort:\n");
writelines(lineptr, nlines);
return 0;
} else {
printf("input too bit to sort\n");
return 1;
}
}
示例5: main
/* sort input lines */
main(int argc, char *argv[])
{
int nlines,reverse = 1; /* number of input lines read */
int numeric = 0; /* 1 if numeric sort */
while(--argc > 0 && (*++argv)[0] == '-') {
int c;
while( c = *++argv[0] ) {
switch(c) {
case 'n':
numeric = 1;
break;
case 'r':
reverse = -1;
break;
}
}
}
if ((nlines = readlines(lineptr, MAXLINES)) >= 0) {
qsort((void**) lineptr, 0, nlines-1, reverse,
(int (*)(void*,void*))(numeric ? numcmp : strcmp));
writelines(lineptr, nlines);
getchar();
return 0;
} else {
printf("input too big to sort\n");
return 1;
}
}
示例6: main
int main(int argc, char *argv[]) {
int nlines, numeric = 0, reverse = 0;
while (*++argv) {
if (**argv == '-') {
while (*++*argv) {
if (**argv == 'r') {
reverse = 1;
}
if (**argv == 'n') {
numeric = 1;
}
}
} else {
printf("format error: sort -rn\n");
exit(0);
}
}
if (argc > 1 && strcmp(argv[1], "-n") == 0) {
numeric = 1;
}
if ((nlines = readlines(lineptr, MAXLINES)) >= 0) {
qsortx((void **)lineptr, 0, nlines-1,
(int (*)(void *, void *))(numeric ? numcmp : strcmp));
writelines(lineptr, nlines, reverse);
return 0;
} else {
printf("error: inut too big to sort\n");
return -1;
}
}
示例7: main
int main(int argc, char **argv)
{
// save lines inputed in a pointer array
int lines, revert, fold, directory;
fold = directory = 0;
revert = 1;
// Use dynamic allocation memory: Umm... maybe in the next time.
char alloc[ALLOCSIZE];
char *ptarr[MAXLINES];
// Check argument
while (--argc > 0 && (*++argv)[0] == '-')
{
char *p;
p = argv[0];
if (!setopt(p,&directory, &revert, &fold))
{
youneedhelp();
return EXIT_FAILURE;
}
}
while ((lines = readlines(ptarr, MAXLINES, alloc)) > 0)
{
// any pointer can be cast to void * and back again without loss of information.
int (*comp)(void *, void *, int);
// Is it too long :(
comp = (int (*)(void *, void *, int))(directory ? strdfcmp : strfcmp);
// sorting use quick sort algorithm.
myqsort((void**)ptarr, 0, lines-1, comp, fold, revert);
writelines(ptarr,lines);
}
return EXIT_SUCCESS;
}
示例8: main
/* sort input lines */
int main(int argc, char **argv)
{
int nlines; /* number of input lines read */
int numeric = 0; /* 1 if numeric sort */
#ifndef ORIGINAL
int reverse = 0;
char lineptr2[MAXLINES][MAXLEN];
nlines = MAXLINES;
while (nlines-- > 0) {
lineptr[nlines] = lineptr2[nlines];
}
while (*++argv) {
if (strcmp(*argv, "-r") == 0) {
reverse = 1;
} else if (strcmp(*argv, "-n") == 0) {
numeric = 1;
}
}
#else
if (argc > 1 && strcmp(argv[1], "-n") == 0) {
numeric = 1;
}
#endif
if ((nlines = readlines(lineptr, MAXLINES)) >= 0) {
qsort((void **)lineptr, 0, nlines - 1,
(int (*)(void *, void*))(numeric == 1 ? numcmp : strcmp));
writelines(lineptr, nlines, reverse);
return 0;
} else {
printf("error: input too big to sort\n");
return 1;
}
}
示例9: main
/*Program starts*/
int main(int argc, char *argv[])
{
int nlines; /* number of input lines read */
int numeric = 0; /* 1 if numeric sort */
int reverse = 0; /* 1 if reverse sort */
int foldcase = 0; /* 1 if folding case */
int dirorder = 0; /* 1 if "directory order" comparision */
/* storage supplied by main */
char linebuf[MAXLEN * MAXLINES];
/* check options */
if (argc > 1)
if (getopt(argv, &numeric, &reverse, &foldcase, &dirorder) == -1)
return 2;
/* read - sort - write */
if ((nlines = readlines(lineptr, linebuf, MAXLINES)) > 0)
{
qsort1((void **) lineptr, 0, nlines -1,
(int (*)(void *, void *))(numeric ? numcmp : (foldcase ? strcasecmp
: strcmp)), reverse, dirorder);
writelines(lineptr, nlines);
return 0;
}
else
{
printf("error: input too big to sort\n");
return 1;
}
return 0;
}
示例10: main
int main( int argc, char *argv[])
{
int nlines; /* number of input lines read */
int c, numeric = 0, reverse = 0; /*flags for options */
while(--argc > 0 && (*++argv)[0] == '-')
while(c = *++argv[0])
switch(c) {
case 'n':
numeric = 1;
break;
case 'r':
reverse = 1;
break;
default:
printf("sort: illegal option %c\n",c);
break;
}
if((nlines = readlines(lineptr,MAXLINES)) >= 0) {
qsort((void **) lineptr, 0, nlines-1, (int (*)(void*,void*))(numeric ? numcmp : strcmp),reverse);
writelines(lineptr,nlines);
return 0;
} else {
printf("input too big to sort \n");
return 1;
}
}
示例11: main
/* sort input lines */
int main(int argc, char *argv[])
{
char *lineptr[MAXLINES]; /* pointers to text lines */
int nlines; /* number of input lines read */
int numeric = 0; /* 1 if numeric sort */
/* If the optional argument -n is given, it will sort the input lines
* numerically instead of lexicographically.
*/
if (argc > 1 && strCmp(argv[1], "-n") == 0)
numeric = 1;
/* lineptr是一个指针,指向的变量类型是char *, 则lineptr对应的数据类型是
* char **,后面一个 * 表示这是一个指针,前面的char * 表示指针指向的类型
* 是 char *; 所以要下面使用 void ** 来进行强制转换,而不是 void *
*/
if ((nlines = readlines(lineptr, MAXLINES)) >= 0) {
qsort((void **)lineptr, 0, nlines - 1,
(int (*)(const void*, const void*))(numeric ? numcmp : strCmp));
printf("-------------After sort----------\n");
writelines(lineptr, nlines);
return 0;
}
else {
printf("error: input too big to sort\n");
return 1;
}
}
示例12: main
int main(int argc, char **argv)
{
int nlines;
unsigned opts = 0;
while(*++argv != NULL) {
if((*argv)[0] == '-') {
while(*++*argv) {
switch(**argv) {
case 'n':
opts |= OPT_NUMERIC;
break;
case 'r':
opts |= OPT_REVERSE;
break;
}
}
}
}
if((nlines = readlines(lineptr, MAXLINES)) >= 0) {
qsort_lomuto((void **) lineptr, 0, nlines-1,
(int (*)(void *, void *))(opts & OPT_NUMERIC ? numcmp : strcmp), opts);
writelines(lineptr, nlines);
return 0;
} else {
printf("Input too large to sort.\n");
return 1;
}
}
示例13: main
int main(int argc, char *argv[]){
char numeric = 0;
char reverse = 0;
char caseInsensitive = 0;
int nlines;
char lines[MAXLINES*MAXLEN];
int arg = 1;
while(arg < argc){
if(strcmp(argv[arg], "-n") == 0){
numeric = 1;
} else if(strcmp(argv[arg], "-r") == 0){
reverse = 1;
} else if(strcmp(argv[arg], "-f") == 0){
caseInsensitive = 1;
}
arg++;
}
if((nlines = readlines(linesptr, lines, MAXLINES)) >= 0){
qsort2((void **) linesptr, 0, nlines-1, (numeric ? numcmp : caseInsensitive ? strcasecmp : strcmp));
writelines(linesptr, nlines, reverse);
return 0;
} else {
printf("input too big to sort\n");
return 1;
}
}
示例14: main
int main(int argc, char *argv[])
{
int nlines;
int numeric = 0;
int asc = 1;
int i;
while (argc-- > 1) {
if (strcmp(argv[argc], "-n") == 0)
numeric = 1;
else if (strcmp(argv[argc], "-r") == 0)
asc = -1;
}
if (argc > 1 && strcmp(argv[1], "-n") == 0)
numeric = 1;
if ((nlines = readlines(lineptr, MAXLINES)) >= 0) {
myqsort((void **) lineptr, 0, nlines-1,
(int (*)(void*,void*))(numeric ? numcmp : strcmp), asc);
writelines(lineptr, nlines);
return 0;
} else {
printf("input too big to sort\n");
return 1;
}
}
示例15: impl
void impl( char * path )
{
FILE * fp = fopen(path,"rb");
if( !fp )
{
perror(path);
return;
}
int nlines = 0;
char * lineptr[MAXLINES];
if( (nlines = readlines( fp, lineptr, MAXLINES)) >= 0 )
{
int (*comparator)(void*,void*) =
IS_NUMERIC ? (IS_NUMERIC_FIELD ? ((int(*)(void*,void*))numfieldcmp) : ((int(*)(void*,void*))numcmp) ) :
IS_DICTIONARY ? (IS_DICTIONARY_FIELD ? ((int(*)(void*,void*))strDirectoryOrderFieldcmp) : ((int(*)(void*,void*))strDirectoryOrdercmp) ) :
IS_CASE_INSENSITIVE ? (IS_CASE_INSENSITIVE_FIELD ? ((int(*)(void*,void*))strcaseFieldcmp) : ((int(*)(void*,void*))strcasecmp) ) :
(int(*)(void*,void*))strcmp;
qsort_ex_5_14( (void **)lineptr, 0, nlines - 1, comparator);
writelines( lineptr, nlines);
}
else
{
printf("Error, too many lines to sort, max is %d\n",MAXLINES);
return;
}
fclose(fp);
}