当前位置: 首页>>代码示例>>C++>>正文


C++ readlines函数代码示例

本文整理汇总了C++中readlines函数的典型用法代码示例。如果您正苦于以下问题:C++ readlines函数的具体用法?C++ readlines怎么用?C++ readlines使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了readlines函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: devmain

// USB device main loop
static void* devmain(usbdevice* kb){
    readlines_ctx linectx;
    readlines_ctx_init(&linectx);
    while(1){
        pthread_mutex_lock(dmutex(kb));
        // End thread when the handle is removed
        if(!IS_CONNECTED(kb))
            break;
        // Read from FIFO
        const char* line;
        euid_guard_start;
        int lines = readlines(kb->infifo - 1, linectx, &line);
        euid_guard_stop;
        if(lines){
            if(readcmd(kb, line)){
                // USB transfer failed; destroy device
                closeusb(kb);
                break;
            }
        }
        // Update indicator LEDs for this keyboard. These are polled rather than processed during events because they don't update
        // immediately and may be changed externally by the OS.
        // (also, they can lock the keyboard if they're sent at the wrong time, at least on some firmwares)
        kb->vtable->updateindicators(kb, 0);
        // Wait a little bit and then read again
        pthread_mutex_unlock(dmutex(kb));
        DELAY_SHORT(kb);
    }
    pthread_mutex_unlock(dmutex(kb));
    readlines_ctx_free(linectx);
    return 0;
}
开发者ID:shazron,项目名称:ckb,代码行数:33,代码来源:usb.c

示例2: 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;
  }
}
开发者ID:bnjzer,项目名称:c,代码行数:29,代码来源:sort.c

示例3: 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;
     }
}
开发者ID:jlegoff,项目名称:misc,代码行数:25,代码来源:5-14.c

示例4: main

int main(int argc, char *argv[])
{
	int nlines; /* number of input lines read */
	int numeric = 0; /* 1 if numeric sort */
	int i;

	for (i = 1; i < argc ; i++) {
		if (*argv[i] == '-') {
			switch (*(argv[i] + 1)) {
				case 'n':
					numeric = 1;
					break;
				case 'r':
					order = 1;
					break;
				case 'f':
					fold = 1;
				default:
					break;
			}
		}
	}

	if ((nlines = readlines(lineptr, MAXLINES)) >= 0) {
		q_sort((void**)lineptr, 0, nlines-1,(int(*)(void*, void*))(numeric ? numcmp : (fold ? fstrcmp : strcmp)), order);
		printf("\nResult:\n======\n");
        	writelines(lineptr, nlines);
        	return 0;
	} else {
		printf("error: input too big to sort\n");
		return 1;
	}
}
开发者ID:sushithbalu,项目名称:KandR2-solutions,代码行数:33,代码来源:15.c

示例5: 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;
}
开发者ID:danadorneanu,项目名称:portofolio,代码行数:60,代码来源:knr_5_14.c

示例6: devmain

// USB device main loop
static void* devmain(usbdevice* kb){
    // dmutex should still be locked when this is called
    int kbfifo = kb->infifo - 1;
    readlines_ctx linectx;
    readlines_ctx_init(&linectx);
    while(1){
        pthread_mutex_unlock(dmutex(kb));
        // Read from FIFO
        const char* line;
        int lines = readlines(kbfifo, linectx, &line);
        pthread_mutex_lock(dmutex(kb));
        // End thread when the handle is removed
        if(!IS_CONNECTED(kb))
            break;
        if(lines){
            if(readcmd(kb, line)){
                // USB transfer failed; destroy device
                closeusb(kb);
                break;
            }
        }
    }
    pthread_mutex_unlock(dmutex(kb));
    readlines_ctx_free(linectx);
    return 0;
}
开发者ID:gtjoseph,项目名称:ckb,代码行数:27,代码来源:usb.c

示例7: 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;
  }
}
开发者ID:bmkessler,项目名称:The_C_Programming_Language,代码行数:28,代码来源:sort.c

示例8: main

int main(int argc, char* argv[]) {
	if (argc != 2) {
		std::cout << "Need filename" << std::endl;
		return -1;
	}
	char* filename = argv[1];

	std::vector<std::string*>* strReps = readlines(filename);

	std::vector<std::vector<int>*>* vectorReps = map(strReps, &transform);

	std::vector<int>* vectorRes = sum(vectorReps);

	std::string* strRes = transform_1(vectorRes);

	std::cout << *strRes << std::endl;

	assert((*strRes).substr(0, 10) == std::string("5537376230"));
	

	for (int i = 0; i < strReps->size(); i++) {
		delete strReps->at(i);
	}
	delete strReps;
	for (int i = 0; i < vectorReps->size(); i++) {
		delete vectorReps->at(i);
	}
	delete vectorReps;
	delete vectorRes;
	delete strRes;
	return 0;
}
开发者ID:ejconlon,项目名称:cppeuler,代码行数:32,代码来源:ex13.cpp

示例9: 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);
}
开发者ID:markmontymark,项目名称:knr-c,代码行数:31,代码来源:5-17.c

示例10: 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;
	}
}
开发者ID:devilTian,项目名称:Fragment,代码行数:31,代码来源:5-14.c

示例11: main

// sort input lines
int main(int argc, char *argv[]) {
	int nlines;
	int (*cmpfunc)(void*,void*) = (int (*)(void*,void*)) strcmp;
	int direction = 1;	// sorting normally (low -> high)

	while (--argc > 0 && (*++argv)[0] == '-')
		while (*++argv[0])
			switch (*argv[0]) {
			case 'n':	// numerically
				cmpfunc = (int (*)(void*,void*)) numcmp;
				break;
			case 'r':	// reverse
				direction = -1;
				break;
			case 'f':	// fold cases
				cmpfunc = (int (*)(void*,void*)) strcmpf;
				break;
			default:
				printf("Unknown option '%c'\n", *argv[0]);
				argc = 0;
				break;
			}
	if (argc < 0) {
		printf("Usage: sortlines [-n] [-r] [-f]\n");
		return 1;
	} else if ((nlines = readlines(lineptr, MAXLINES)) >= 0) {
		qsortf((void **) lineptr, 0, nlines-1, cmpfunc, direction);
		writelines(lineptr, nlines);
		return 0;
	} else {
		printf("input too big to sort\n");
		return 1;
	}
}
开发者ID:Prince781,项目名称:k-and-r,代码行数:35,代码来源:sortlines2.c

示例12: 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;
	}
}
开发者ID:liudongmiao,项目名称:tcpl,代码行数:36,代码来源:5.14.c

示例13: 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;
}
开发者ID:ducanhng,项目名称:ctuto,代码行数:34,代码来源:ex5_14v2.c

示例14: 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;
}
开发者ID:1sps,项目名称:knr,代码行数:33,代码来源:5-16.c

示例15: main

int main(int argc, char *argv[])
{
	int nlines, i;
	int numeric = 0;
	int sort_dir = ASC; /* positive 1 for ascending, negative 1 for descending */

	/* check command line arguments and toggle flags*/
	for(i = 1; i < argc; i++){
		if(*argv[i] == '-'){;
			if(strchr(argv[i], 'n') != NULL){
				numeric = 1;
			}
			
			if(strchr(argv[i], 'r') != NULL){
				sort_dir = DESC;
			}
		}
	}

	if((nlines = readlines(lineptr, MAXLINES)) >= 0){
		sm_qsort((void**) lineptr, 0, nlines-1, (int (*)(const void*, const void*, const int))(numeric ? numcmp : sm_strcmp), sort_dir);
		writelines(lineptr, nlines);
		return 0;
	}
	else{
		printf("input too big to sort\n");
		return 1;
	}
}
开发者ID:stephenmerendino,项目名称:k-r-exercises,代码行数:29,代码来源:ex14.c


注:本文中的readlines函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。