當前位置: 首頁>>代碼示例>>C++>>正文


C++ GetLine函數代碼示例

本文整理匯總了C++中GetLine函數的典型用法代碼示例。如果您正苦於以下問題:C++ GetLine函數的具體用法?C++ GetLine怎麽用?C++ GetLine使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了GetLine函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: main

int main(int argc,char **argv)
{
  int curr_arg;
  bool bDebug;
  bool bVerbose;
  bool bHaveDateString;
  char *date_string;
  bool bGetDateFromCwd;
  bool bPosNeg;
  int retval;
  int offset;
  FILE *fptr;
  int linelen;
  int line_no;
  int number;
  int work;
  int total;
  int positive_total;
  int negative_total;

  if ((argc < 2) || (argc > 8)) {
    printf(usage);
    return 1;
  }

  bDebug = false;
  bVerbose = false;
  bHaveDateString = false;
  bGetDateFromCwd = false;
  bPosNeg = false;
  offset = 0;

  for (curr_arg = 1; curr_arg < argc; curr_arg++) {
    if (!strcmp(argv[curr_arg],"-debug"))
      bDebug = true;
    else if (!strcmp(argv[curr_arg],"-verbose"))
      bVerbose = true;
    else if (!strncmp(argv[curr_arg],"-offset",7))
      sscanf(&argv[curr_arg][7],"%d",&offset);
    else if (!strncmp(argv[curr_arg],"-date",5)) {
      date_string = &argv[curr_arg][5];
      bHaveDateString = true;
    }
    else if (!strcmp(argv[curr_arg],"-get_date_from_cwd"))
      bGetDateFromCwd = true;
    else if (!strcmp(argv[curr_arg],"-pos_neg"))
      bPosNeg = true;
    else
      break;
  }

  if (argc - curr_arg != 1) {
    printf(usage);
    return 2;
  }

  if (bHaveDateString && bGetDateFromCwd) {
    printf("can't specify both -date and -get_date_from_cwd\n");
    return 3;
  }

  if (bDebug || bGetDateFromCwd)
    getcwd(save_dir,_MAX_PATH);

  if (bGetDateFromCwd) {
    retval = get_date_from_cwd(save_dir,&date_string);

    if (retval) {
      printf("get_date_from_cwd() failed: %d\n",retval);
      return 4;
    }

    bHaveDateString = true;
  }

  if ((fptr = fopen(argv[curr_arg],"r")) == NULL) {
    printf(couldnt_open,argv[curr_arg]);
    return 5;
  }

  line_no = 0;
  total = 0;

  if (bPosNeg) {
    positive_total = 0;
    negative_total = 0;
  }

  for ( ; ; ) {
    GetLine(fptr,line,&linelen,MAX_LINE_LEN);

    if (feof(fptr))
      break;

    line_no++;

    sscanf(&line[offset],"%d %d",&number,&work);
    work *= number;

    total += work;
//.........這裏部分代碼省略.........
開發者ID:neostreet,項目名稱:command_line_tools,代碼行數:101,代碼來源:add_multf_int.c

示例2: main

int main(int argc,char **argv)
{
  int m;
  int n;
  int curr_arg;
  bool bDebug;
  int player_name_ix;
  int player_name_len;
  FILE *fptr0;
  int filename_len;
  FILE *fptr;
  int line_len;
  int line_no;
  int ix;
  int file_no;

  if ((argc < 3) || (argc > 4)) {
    printf(usage);
    return 1;
  }

  bDebug = false;

  for (curr_arg = 1; curr_arg < argc; curr_arg++) {
    if (!strcmp(argv[curr_arg],"-debug")) {
      bDebug = true;
      getcwd(save_dir,_MAX_PATH);
    }
    else
      break;
  }

  if (argc - curr_arg != 2) {
    printf(usage);
    return 2;
  }

  player_name_ix = curr_arg++;
  player_name_len = strlen(argv[player_name_ix]);

  if ((fptr0 = fopen(argv[curr_arg],"r")) == NULL) {
    printf(couldnt_open,argv[curr_arg]);
    return 3;
  }

  file_no = 0;

  for ( ; ; ) {
    GetLine(fptr0,filename,&filename_len,MAX_FILENAME_LEN);

    if (feof(fptr0))
      break;

    file_no++;

    if ((fptr = fopen(filename,"r")) == NULL) {
      printf(couldnt_open,filename);
      continue;
    }

    line_no = 0;

    for ( ; ; ) {
      GetLine(fptr,line,&line_len,MAX_LINE_LEN);

      if (feof(fptr))
        break;

      line_no++;

      if (Contains(true,
        line,line_len,
        argv[player_name_ix],player_name_len,
        &ix)) {

        if (!strncmp(line,dealt_to,DEALT_TO_LEN)) {
          for (n = 0; n < line_len; n++) {
            if (line[n] == '[')
              break;
          }

          if (n < line_len) {
            n++;

            for (m = n; m < line_len; m++) {
              if (line[m] == ']')
                break;
            }

            if (m < line_len) {
              line[m] = 0;

              if (!bDebug)
                printf("%s\n",&line[n]);
              else
                printf("%s %s\\%s\n",&line[n],save_dir,filename);

              continue;
            }
          }
//.........這裏部分代碼省略.........
開發者ID:yawecodin,項目名稱:misc_poker_utilities,代碼行數:101,代碼來源:fdealt_to3.c

示例3: PrintInstructions2

void PrintInstructions2()
{
	printf("\nThe Game is going to start . Press any key when you are ready.");
	GetLine();
	printf("\nTo pause,click mouse on the graph.\n");
}
開發者ID:jarvis-huang,項目名稱:CPP,代碼行數:6,代碼來源:Darwin.c

示例4: PreviewSubTask

void PreviewSubTask()
#endif
{
#ifndef __PPC__
	struct SubTask *st;
#endif
	BOOL done = FALSE, working = FALSE, init = FALSE, stop = FALSE;
	int y;
	struct SubTaskMsg *stm;
	struct PreviewData *data;
	rsiSMALL_COLOR *line;

#ifndef __PPC__
	st = InitSubTask();
#endif
	if(st)
	{
		/*
		** after the sub task is up and running, we go into
		** a loop and process the messages from the main task.
		*/
		while(!done)
		{
			while((stm = (struct SubTaskMsg *)WARPOS_PPC_FUNC(GetMsg)(st->st_Port)))
			{
				switch(stm->stm_Command)
				{
					case STC_SHUTDOWN:
						// This is the shutdown message from KillSubTask().
						done = TRUE;
						working = FALSE;
						break;
					case STC_CLEANUP:
						working = FALSE;
						if(data->preview)
						{
#ifdef __MIXEDBINARY__
							PreviewDelete(data->preview);
#else
							delete data->preview;
#endif
							data->preview = NULL;
						}
						break;
					case STC_START:
						working = TRUE;
						stop = FALSE;
						init = FALSE;
						data = (struct PreviewData*)stm->stm_Parameter;
#ifdef __MIXEDBINARY__
						data->preview = PreviewCreate();
#else
						data->preview = new PREVIEW;
#endif
						if(!data->preview)
							done = TRUE;
						break;
					case STC_STOP:
						stop = TRUE;
						break;
					case STC_RESUME:
						stop = FALSE;
						break;
				}

				/*
				** If we received a shutdown message, we do not reply it
				** immediately. First, we need to free our resources.
				*/
				if(done)
					break;
				WARPOS_PPC_FUNC(ReplyMsg)((struct Message *)stm);
			}
			if(working && !stop)
			{
				if(!init)
				{
#ifdef __MIXEDBINARY__
					if(Init(data->preview, data->width, data->height, LINES, data->surf, data->object))
#else
					if(data->preview->Init(data->width, data->height, LINES, data->surf, data->object))
#endif
					{
						init = TRUE;
						DOMETHOD(app, MUIM_Application_PushMethod, data->msghandler, 4, MUIM_MsgHandler_PushMessage, data->renderarea, 1, MUIM_Render_ResetColors);
						DOMETHOD(app, MUIM_Application_PushMethod, data->msghandler, 6, MUIM_MsgHandler_PushMessage, data->renderarea, 3, MUIM_Set, MUIA_Render_SubTask, st);
#ifdef __MIXEDBINARY__
						DOMETHOD(app, MUIM_Application_PushMethod, data->msghandler, 6, MUIM_MsgHandler_PushMessage, data->renderarea, 3, MUIM_Set, MUIA_Render_Data, GetLine(data->preview));
#else
						DOMETHOD(app, MUIM_Application_PushMethod, data->msghandler, 6, MUIM_MsgHandler_PushMessage, data->renderarea, 3, MUIM_Set, MUIA_Render_Data, data->preview->GetLine());
#endif
						DOMETHOD(app, MUIM_Application_PushMethod, data->msghandler, 6, MUIM_MsgHandler_PushMessage, data->renderarea, 3, MUIM_Set, MUIA_Render_Lines, LINES);
						y = 0;
					}
					else
					{
						working = FALSE;
					}
				}

//.........這裏部分代碼省略.........
開發者ID:Kalamatee,項目名稱:RayStorm,代碼行數:101,代碼來源:subtask.cpp

示例5: Kiface

void CVPCB_MAINFRAME::AssocieModule( wxCommandEvent& event )
{
    FOOTPRINT_ALIAS_LIST aliases;
    FOOTPRINT_ALIAS*     alias;
    COMPONENT*           component;
    wxFileName           fn;
    wxString             msg, tmp;
    char                 Line[1024];
    FILE*                file;
    size_t               ii;

    SEARCH_STACK&        search = Kiface().KifaceSearch();

    if( m_netlist.IsEmpty() )
        return;

    // Find equivalents in all available files.
    for( ii = 0; ii < m_AliasLibNames.GetCount(); ii++ )
    {
        fn = m_AliasLibNames[ii];

        if( !fn.HasExt() )
        {
            fn.SetExt( FootprintAliasFileExtension );
            // above fails if filename has more than one point
        }
        else
        {
            fn.SetExt( fn.GetExt() + wxT( "." ) + FootprintAliasFileExtension );
        }

        tmp = search.FindValidPath( fn.GetFullPath() );

        if( !tmp )
        {
            msg.Printf( _( "Footprint alias library file '%s' could not be found in the "
                           "default search paths." ),
                        GetChars( fn.GetFullName() ) );
            wxMessageBox( msg, FMT_TITLE_LIB_LOAD_ERROR, wxOK | wxICON_ERROR );
            continue;
        }

        file = wxFopen( tmp, wxT( "rt" ) );

        if( file == NULL )
        {
            msg.Printf( _( "Error opening alias library '%s'." ), GetChars( tmp ) );
            wxMessageBox( msg, FMT_TITLE_LIB_LOAD_ERROR, wxOK | wxICON_ERROR );
            continue;
        }

        while( GetLine( file, Line, NULL, sizeof(Line) ) != NULL )
        {
            char* text = Line;
            wxString value, footprint, wtext = FROM_UTF8( Line );

            value = GetQuotedText( wtext );

            if( text == NULL || ( *text == 0 ) || value.IsEmpty() )
                continue;

            footprint = GetQuotedText( wtext );

            if( footprint.IsEmpty() )
                continue;

            value.Replace( wxT( " " ), wxT( "_" ) );

            alias = new FOOTPRINT_ALIAS();
            alias->m_Name = value;
            alias->m_FootprintName = footprint;
            aliases.push_back( alias );
        }

        fclose( file );
    }

    // Display the number of footprint aliases.
    msg.Printf( _( "%d footprint aliases found." ), aliases.size() );
    SetStatusText( msg, 0 );

    m_skipComponentSelect = true;
    ii = 0;

    for( unsigned kk = 0;  kk < m_netlist.GetCount();  kk++ )
    {
        component = m_netlist.GetComponent( kk );

        bool found = false;
        m_compListBox->SetSelection( ii++, true );

        if( !component->GetFPID().empty() )
            continue;

        BOOST_FOREACH( FOOTPRINT_ALIAS& alias, aliases )
        {

            if( alias.m_Name.CmpNoCase( component->GetValue() ) != 0 )
                continue;

//.........這裏部分代碼省略.........
開發者ID:danstiurca,項目名稱:kicad-source-mirror,代碼行數:101,代碼來源:autosel.cpp

示例6: main

int main(int argc,char **argv)
{
  int m;
  int n;
  int p;
  int curr_arg;
  bool bDebug;
  bool bCount;
  bool bShowZero;
  int reupped_count;
  int player_name_ix;
  int player_name_len;
  FILE *fptr0;
  int filename_len;
  FILE *fptr;
  int line_len;
  int line_no;
  int dbg_line_no;
  int ix;
  int street;
  int num_street_markers;
  int starting_balance;
  int spent_this_street;
  int spent_this_hand;
  int end_ix;
  int uncalled_bet_amount;
  int collected_from_pot;
  int collected_from_pot_count;
  int ending_balance;
  int file_no;
  int dbg_file_no;
  int dbg;
  int work;
  double dwork1;
  double dwork2;
  bool bSkipping;

  if ((argc < 3) || (argc > 6)) {
    printf(usage);
    return 1;
  }

  bDebug = false;
  bCount = false;
  bShowZero = false;

  for (curr_arg = 1; curr_arg < argc; curr_arg++) {
    if (!strcmp(argv[curr_arg],"-debug"))
      bDebug = true;
    else if (!strcmp(argv[curr_arg],"-count"))
      bCount = true;
    else if (!strcmp(argv[curr_arg],"-show_zero")) {
      bShowZero = true;
      bCount = true;
    }
    else
      break;
  }

  if (argc - curr_arg != 2) {
    printf(usage);
    return 2;
  }

  player_name_ix = curr_arg++;
  player_name_len = strlen(argv[player_name_ix]);

  if ((fptr0 = fopen(argv[curr_arg],"r")) == NULL) {
    printf(couldnt_open,argv[curr_arg]);
    return 3;
  }

  file_no = 0;
  dbg_file_no = -1;

  for ( ; ; ) {
    GetLine(fptr0,filename,&filename_len,MAX_FILENAME_LEN);

    if (feof(fptr0))
      break;

    strcpy(prev_filename,filename);
    file_no++;

    if (dbg_file_no == file_no)
      dbg = 1;

    if ((fptr = fopen(filename,"r")) == NULL) {
      printf(couldnt_open,filename);
      continue;
    }

    line_no = 0;
    ending_balance = -1;
    reupped_count = 0;

    for ( ; ; ) {
      GetLine(fptr,line,&line_len,MAX_LINE_LEN);

      if (feof(fptr))
//.........這裏部分代碼省略.........
開發者ID:neostreet,項目名稱:misc_poker_utilities,代碼行數:101,代碼來源:freupped3.c

示例7: Execute

DWORD WINAPI Execute(LPDWORD data)
{
	int i, linenumber;
	char line[256], buf[256], logbuf[100], *prog;
	BOOL error = FALSE;

	obj = NULL;
	light = NULL;

	ULONG arg[MAXARGS];

	for (i = 0; i < MAXARGS; i++)
		arg[i] = NULL;

	prog = ((THREAD_DATA *)data)->szProg;
	pDisplay = ((THREAD_DATA *)data)->pDisplay;
	strcpy(szIncludePath, "");
	strcpy(szPicturePath, "");

	err = rsiSetLogCB(Log);
	if (err)
	{
		rsiGetErrorMsg(buf,err);
		Log(buf);
	}

	err = rsiSetUpdateStatusCB(UpdateStatus);
	if (err)
	{
		rsiGetErrorMsg(buf,err);
		Log(buf);
	}

	err = rsiSetCheckCancelCB(CheckCancel);
	if (err)
	{
		rsiGetErrorMsg(buf,err);
		Log(buf);
	}

	err = rsiSetCooperateCB(Cooperate);
	if (err)
	{
		rsiGetErrorMsg(buf,err);
		Log(buf);
	}

	linenumber = 0;
	include = 0;

	while ((*prog || include > 0) && !error)
	{ 
		GetLine(&prog, line, &linenumber);
		// read command first
		if (!Scan(line, buf, arg))
		{
			i = 0;
			// find command in list	
  			while (commands[i].name && stricmp(buf, commands[i].name))
  		 		i++;
				
			// call corresponding function with "arg" as argument
			if (commands[i].func)
				error = commands[i].func(arg);
			else
				error = ERROR_UNKNOWNCOM;
				
			for (i = 0; i < MAXARGS; i++)
			{
				if (arg[i])
					delete (ULONG *)arg[i];
				arg[i] = NULL;
			}

			if (error)
			{
				if (include)
				{
					sprintf(logbuf, "In include file: \"%s\"", Includefile[include].name);
					pDisplay->Log(logbuf);
					linenumber = Includefile[include].linenumber;
				}
				sprintf(logbuf, "Error executing command in line %i", linenumber);
				pDisplay->Log(logbuf);
				pDisplay->Log(line);
				GetError(logbuf, error);
				pDisplay->Log(logbuf);
			}
		}
	}
	if (error)
	{
		pDisplay->Log("Error occurred");
		pDisplay->Log("Cancel execution");
		// close open include files
		while (include > 0)
		{
			if (Includefile[include].hFile)
				fclose(Includefile[include].hFile);
			include--;
//.........這裏部分代碼省略.........
開發者ID:Kalamatee,項目名稱:RayStorm,代碼行數:101,代碼來源:parser.cpp

示例8: main


//.........這裏部分代碼省略.........
  if (bDelta && bStartingBalance) {
    printf("can't specify both -delta and -starting_balance\n");
    return 3;
  }

  player_name_ix = curr_arg++;
  player_name_len = strlen(argv[player_name_ix]);

  if ((fptr0 = fopen(argv[curr_arg],"r")) == NULL) {
    printf(couldnt_open,argv[curr_arg]);
    return 4;
  }

  ending_balance = -1;
  prev_ending_balance = -1;

  if (bDelta) {
    max_delta = -1;
    min_delta = 1;
  }
  else if (bStartingBalance) {
    max_starting_balance = -1;
    min_starting_balance = 1;
  }
  else {
    max_ending_balance = -1;
    min_ending_balance = 1;
  }

  file_no = 0;
  dbg_file_no = -1;

  for ( ; ; ) {
    GetLine(fptr0,filename,&filename_len,MAX_FILENAME_LEN);

    if (feof(fptr0))
      break;

    file_no++;

    if (dbg_file_no == file_no)
      dbg = 1;

    if ((fptr = fopen(filename,"r")) == NULL) {
      printf(couldnt_open,filename);
      continue;
    }

    line_no = 0;
    street = 0;
    num_street_markers = 0;
    ante = 0;
    bring_in = 0;
    spent_this_street = 0;
    spent_this_hand = 0;
    uncalled_bet_amount = 0;
    collected_from_pot = 0;
    collected_from_pot_count = 0;

    for ( ; ; ) {
      GetLine(fptr,line,&line_len,MAX_LINE_LEN);

      if (feof(fptr))
        break;

      line_no++;
開發者ID:neostreet,項目名稱:misc_poker_utilities,代碼行數:67,代碼來源:fhand_bal.c

示例9: IsFunctioning

//=====================================================================
bool Rowind::IsFunctioning() {
	if(GetLine() != Null) {
		return true;
	}
	return false;
}
開發者ID:bobalong,項目名稱:Rowind,代碼行數:7,代碼來源:Rowind.cpp

示例10: read_ozone

int read_ozone(char* fname, short int** out_data, int* doy, int* year, int* nlats,
               int* nlons, float* minlat, float* minlon, float* maxlat,
               float* maxlon, float* latsteps, float* lonsteps,
               float* lat_array, float* lon_array)
{ 
 FILE *fp;
 char line[MAX_STR_LEN+1];
 char dtype[10],month[4],valbuf[4];
 char c_day_of_month[3];
 int day_of_month;
 int irow,icol,i=0,ival;
 int ilat;
 int number;
 short int* data;
 float mylat;
 float comp_lat,comp_lon;
 char hemisphere1, hemisphere2;
 /*
 Day: 260 Sep 17, 2001    EP/TOMS    NRT OZONE    GEN:01.271 Asc LECT: 11:09 AM 
012345678 1 2345678 2 2345678 3 2345678 4 2345678 5 2345678 6 2345678 7 2345678
 Longitudes:  288 bins centered on 179.375 W to 179.375 E  (1.25 degree steps)  
 Latitudes :  180 bins centered on  89.5   S to  89.5   N  (1.00 degree steps)  
 */

 fp = fopen(fname, "r");
 GetLine(fp,line);
 sscanf(line," Day: %3d ",doy);
 strncpy(month,&line[10],3); month[3]='\0';
 strncpy(c_day_of_month,&line[14],2); c_day_of_month[2]='\0';
 strncpy(dtype,&line[26],7); dtype[7]='\0';
 day_of_month= atoi( c_day_of_month );
 *year= atoi( &line[18] );
 printf("year=%d month=%s day_of_month=%d\n",*year,month,day_of_month);

 GetLine(fp,line);
 sscanf(line," Longitudes:  %3d bins centered on %7f W to %7f E  (%5f ", 
        nlons, minlon, maxlon, lonsteps);
 /* OMI data used different index - Feng */
 if(strstr(fname, "omi")) {
   hemisphere1= line[42];  hemisphere2= line[55];  
 }
 else {
 hemisphere1= line[43];  hemisphere2= line[56];
 } 
 *minlon *= (hemisphere1=='S'||hemisphere1=='W'?-1.0:1.0);
 *maxlon *= (hemisphere2=='S'||hemisphere2=='W'?-1.0:1.0);

 GetLine(fp,line);
 sscanf(line," Latitudes :  %3d bins centered on %7f S to %7f N  (%4f ",
        nlats, minlat, maxlat, latsteps);
 /* OMI data used different index - Feng */
 if(strstr(fname, "omi")) {
   hemisphere1= line[42];  hemisphere2= line[55];  
 }
 else {
 hemisphere1= line[43];  hemisphere2= line[56]; 
 }
 *minlat *= (hemisphere1=='S'||hemisphere1=='W'?-1.0:1.0);
 *maxlat *= (hemisphere2=='S'||hemisphere2=='W'?-1.0:1.0);

 comp_lat= *minlat;
 comp_lon= *minlon;

 data = (short int *)calloc(((*nlats)*(*nlons)), sizeof(short int));

 for (icol=0; icol<*nlons; icol++)
   {
   lon_array[icol]= comp_lon;
   comp_lon += *lonsteps;
   } 

 ilat=0;
 for (irow=0; irow<*nlats; irow++)
 {
   ival=0;
   for (icol=0; icol<NLINE; icol++)
     {
     GetLine(fp,line);
     for ( i=0; i<(icol<(NLINE-1)?longline:shortline); i++ )
       {
       
       strncpy(valbuf,&line[i*3+1],3);
       valbuf[3]='\0';
       sscanf(valbuf,"%3d",&number); 
       data[(*nlats-ilat-1)*(*nlons)+ival++]= number;
       /*
       sscanf(&line[i*3+1],"%3d",&data[ival++]);
       */
       }
     }
   sscanf(&line[i*3+1],"   lat =   %f",&mylat);
   if (0 )   printf("*** in=(%s) mylat=(%f) complat=(%f) ***\n",&line[i*3+1],mylat,comp_lat);
   lat_array[*nlats-ilat-1]= comp_lat;
   comp_lat += *latsteps;
   ilat++;
 }

 *out_data= data;
 return 0;
}
開發者ID:Jwely,項目名稱:ledaps,代碼行數:100,代碼來源:convert_ozone.c

示例11: main

void main(void)
{	
	M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts
	M8C_EnableIntMask(INT_MSK1, INT_MSK1_DBB01); // Enable DBB01 Interrupt for TempCounter
	M8C_EnableIntMask(INT_MSK1, INT_MSK1_DBB11); // Enable DBB01 Interrupt for MotorDriver
	M8C_EnableIntMask(INT_MSK0, INT_MSK0_GPIO); // Enable GPIO interrupt for Tout
	
	// Start the UART(with no parity), LCD, TempCounter and MotorDriver
	UART_Start(UART_PARITY_NONE);
	LCD_Start();
	TempCounter_EnableInt(); // Enable interrupts for counter
	TempCounter_Start();
	MotorDriver_EnableInt(); // Enable interrupts for counter
	
	// Start I2CHW
	I2CHW_Start();
	I2CHW_EnableMstr();
	I2CHW_EnableInt();
	
	WriteI2C(slaveAddress, 0xAC, 1, 0x02); // Write to access config, sets mode to cooling(POL = 1), also turns 1-SHOT off, continuous conversions
	
	WriteI2C(slaveAddress, 0xA1, 2, (setTemp + tolerance), 0x00); // Sets initial high temp to be setTemp + tolerance
	WriteI2C(slaveAddress, 0xA2, 2, (setTemp - tolerance), 0x00); // Sets initial low temp to be setTemp - tolerance
	WriteI2C(slaveAddress, 0xEE, 0); // This tells the temperature IC to start converting the temperatures
	
	// Writes initial string to LCD. When LCD is updated, only the numbers will be changed
	LCD_Position(0,0); LCD_PrCString("CUR: 00 OFF     ");
	LCD_Position(1,0); LCD_PrCString("SET: 00 FAN OFF ");
	
	// This is the command usage string
	UART_CPutString("#################### Heating/Cooling Stepper Motors ##################\r\n\
#	S ##\r\n\
#		S - Set the desired Temperature\r\n\
#		## - Desired temperature in celsius\r\n\
#\r\n\
#	T ##\r\n\
#		T - Set the desired tolerance\r\n\
#		## - Desired tolerance in celsius\r\n\
#\r\n\
#	M X\r\n\
#		M - Change the mode of the thermostat\r\n\
#		X - C is for cool, H is for heat, F is for off\r\n\
#\r\n\
#	F X S\r\n\
#		F - Change the mode of the fan\r\n\
#		X - A is for automatic fan control, M is for always on\r\n\
#		S - Speed of the fan, H = high, M = medium, L = low\r\n\
#####################################################################\r\n");
	while (1)
	{
		char *cmd;
		char *params;
		
		if (GetLine(buf, &strPos, 79)) // Only process the data if GetLine returns true
		{
			cmd = Lowercase(cstrtok(buf, " ")); // Lowercase the first word from the inputted string
			
			if (strlen(cmd) == 1 && cmd[0] == 's') // If the person entered s
			{	
				int temp;
			
				params = cstrtok(0x00, " "); // Read next word 							
				// If next word isnt number or isnt 1 or 2 characters long, then return error
				if (!IsNumber(params) || strlen(params) < 1 || strlen(params) > 2 || csscanf(params, "%d", &temp) != 1) goto error;
				
				// If there is additional data at end of string or if number is not within 0-99, return error
				if (cstrtok(0x00, " ") != 0x00) goto error;
				if ( temp > 99 || temp < 0) goto error; 
				
				setTemp = temp;
				WriteI2C(slaveAddress, 0xA1, 2, (setTemp + tolerance), 0x00); // Sets high temp to be setTemp + tolerance
				WriteI2C(slaveAddress, 0xA2, 2, (setTemp - tolerance), 0x00); // Sets low temp to be setTemp - tolerance
				updateLCD = TRUE; // Update the LCD
			}
			else if (strlen(cmd) == 1 && cmd[0] == 't') // If the person entered t
			{	
				int tol; 
			
				params = cstrtok(0x00, " "); // Read next word					
				// If next word isnt number or isnt 1 or 2 characters long, then return error
				if (!IsNumber(params) || strlen(params) < 1 || strlen(params) > 2 || csscanf(params, "%d", &tol) != 1) goto error;
				
				// If there is additional data at end of string or if number is not within 0-10, return error
				if (cstrtok(0x00, " ") != 0x00) goto error;
				if (tol < 0 || tol > 10) goto error;
				
				tolerance = tol;
				
				WriteI2C(slaveAddress, 0xA1, 2, (setTemp + tolerance), 0x00); // Sets high temp to be setTemp + tolerance
				WriteI2C(slaveAddress, 0xA2, 2, (setTemp - tolerance), 0x00); // Sets low temp to be setTemp - tolerance
				updateLCD = TRUE; // Update the LCD
				
			}
			else if (strlen(cmd) == 1 && cmd[0] == 'm') // If the person entered m
			{	
				char mode;
			
				params = cstrtok(0x00, " "); // Read next word
				
				// If next word isnt 1 character long, return error
//.........這裏部分代碼省略.........
開發者ID:addisonElliott,項目名稱:ECE381,代碼行數:101,代碼來源:main.c

示例12: main

int main(int argc,char **argv)
{
  int m;
  int n;
  bool bNoSort;
  bool bNot;
  int curr_arg;
  FILE *fptr;
  int line_len;
  int num_sessions;
  int session_ix;
  int delta;
  int session_is_blue;
  int prev_session_is_blue;
  int chara;
  int *sort_ixs;
  int num_blue_streaks;
  int blue_streak_ix;
  int retval;
  char *cpt;
  int cumulative_delta;
  int max_cumulative_delta;

  if ((argc < 2) || (argc > 5)) {
    printf(usage);
    return 1;
  }

  bNoSort = false;
  bAscending = false;
  bNot = false;

  for (curr_arg = 1; curr_arg < argc; curr_arg++) {
    if (!strcmp(argv[curr_arg],"-no_sort"))
      bNoSort = true;
    else if (!strcmp(argv[curr_arg],"-ascending"))
      bAscending = true;
    else if (!strcmp(argv[curr_arg],"-not"))
      bNot = true;
    else
      break;
  }

  if (argc - curr_arg != 1) {
    printf(usage);
    return 2;
  }

  if ((fptr = fopen(argv[curr_arg],"r")) == NULL) {
    printf(couldnt_open,argv[curr_arg]);
    return 3;
  }

  num_sessions = 0;
  num_blue_streaks = 0;
  cumulative_delta = 0;
  max_cumulative_delta = 0;

  for ( ; ; ) {
    GetLine(fptr,line,&line_len,MAX_LINE_LEN);

    if (feof(fptr))
      break;

    if (!line_len)
      continue;

    chara = line[0];

    if (((chara >= 'a') && (chara <= 'z')) ||
        ((chara >= 'A') && (chara <= 'Z')))
      continue;

    sscanf(&line[11],"%d",&delta);

    cumulative_delta += delta;

    if (cumulative_delta > max_cumulative_delta) {
      if (!bNot)
        session_is_blue = 1;
      else
        session_is_blue = 0;

      max_cumulative_delta = cumulative_delta;
    }
    else {
      if (!bNot)
        session_is_blue = 0;
      else
        session_is_blue = 1;
    }

    if ((session_is_blue == 1) && ((num_sessions == 0) || (prev_session_is_blue == 0)))
      num_blue_streaks++;

    num_sessions++;
    prev_session_is_blue = session_is_blue;
  }

  if ((session_info = (struct session_info_struct *)malloc(
//.........這裏部分代碼省略.........
開發者ID:neostreet,項目名稱:misc_poker_utilities,代碼行數:101,代碼來源:session_blue_streaks.c

示例13: ParseInput

int
ParseInput(register DviWidget dw)
{
	int		n, k;
	int		c;
	char		Buffer[BUFSIZ];
	int		NextPage;
	int		otherc;

	StopSeen = 0;

	/*
	 * make sure some state exists
	 */

	if (!dw->dvi.state)
	    push_env (dw);
	for (;;) {
		switch (DviGetC(dw, &c)) {
		case '\n':	
			break;
		case ' ':	/* when input is text */
		case 0:		/* occasional noise creeps in */
			break;
		case '{':	/* push down current environment */
			push_env(dw);
			break;
		case '}':
			pop_env(dw);
			break;
		/*
		 * two motion digits plus a character
		 */
		case '0': case '1': case '2': case '3': case '4':
		case '5': case '6': case '7': case '8': case '9':
			HorizontalMove(dw, (c-'0')*10 +
					   DviGetC(dw,&otherc)-'0');
			/* fall through */
		case 'c':	/* single ascii character */
			DviGetC(dw,&c);
		    	if (c == ' ')
			    break;
			Buffer[0] = c;
			Buffer[1] = '\0';
			(void) PutCharacter (dw, Buffer);
			break;
		case 'C':
			GetWord (dw, Buffer, BUFSIZ);
			(void) PutCharacter (dw, Buffer);
			break;
		case 't':
			Buffer[1] = '\0';
			while (DviGetC (dw, &c) != EOF
			       && c != ' ' && c != '\n') {
				Buffer[0] = c;
				HorizontalMove (dw, PutCharacter (dw, Buffer));
			}
			break;
		case 'u':
			n = GetNumber(dw);
			Buffer[1] = '\0';
			while (DviGetC (dw, &c) == ' ')
				;
			while (c != EOF && c != ' ' && c != '\n') {
				Buffer[0] = c;
				HorizontalMove (dw,
						PutCharacter (dw, Buffer) + n);
				DviGetC (dw, &c);
			}
			break;

		case 'D':	/* draw function */
			(void) GetLine(dw, Buffer, BUFSIZ);
			if (dw->dvi.display_enable)
				ParseDrawFunction(dw, Buffer);
			break;
		case 's':	/* ignore fractional sizes */
			n = GetNumber(dw);
			dw->dvi.state->font_size = n;
			break;
		case 'f':
			n = GetNumber(dw);
			dw->dvi.state->font_number = n;
			break;
		case 'H':	/* absolute horizontal motion */
			k = GetNumber(dw);
			HorizontalGoto(dw, k);
			break;
		case 'h':	/* relative horizontal motion */
			k = GetNumber(dw);
			HorizontalMove(dw, k);
			break;
		case 'w':	/* word space */
			Word (dw);
			break;
		case 'V':
			n = GetNumber(dw);
			VerticalGoto(dw, n);
			break;
		case 'v':
//.........這裏部分代碼省略.........
開發者ID:0xffffffRabbit,項目名稱:NextBSD-1,代碼行數:101,代碼來源:parse.c

示例14: main

int main(int argc,char **argv)
{
  int curr_arg;
  bool bVerbose;
  int ge_val;
  FILE *fptr;
  int line_len;
  int line_no;
  int last_ge_line_no;
  int val;
  int intervening;
  int max_intervening;

  if ((argc < 3) || (argc > 4)) {
    printf(usage);
    return 1;
  }

  bVerbose = false;

  for (curr_arg = 1; curr_arg < argc; curr_arg++) {
    if (!strcmp(argv[curr_arg],"-verbose"))
      bVerbose = true;
    else
      break;
  }

  if (argc - curr_arg != 2) {
    printf(usage);
    return 2;
  }

  sscanf(argv[curr_arg],"%d",&ge_val);

  if ((fptr = fopen(argv[curr_arg+1],"r")) == NULL) {
    printf(couldnt_open,argv[curr_arg+1]);
    return 3;
  }

  line_no = 0;
  last_ge_line_no = 0;
  max_intervening = 0;

  for ( ; ; ) {
    GetLine(fptr,line,&line_len,MAX_LINE_LEN);

    if (feof(fptr))
      break;

    line_no++;

    sscanf(line,"%d",&val);

    if (val >= ge_val) {
      if (!bVerbose)
        printf("%d\n",val);
      else if (!last_ge_line_no)
        printf("%s %d\n",line,line_no);
      else {
        intervening = line_no - (last_ge_line_no + 1);

        if (intervening > max_intervening)
          max_intervening = intervening;

        printf("%s %d (%d)\n",line,line_no,intervening);
      }

      last_ge_line_no = line_no;
    }
  }

  fclose(fptr);

  printf("max_intervening = %d\n",max_intervening);

  return 0;
}
開發者ID:neostreet,項目名稱:misc_poker_utilities,代碼行數:77,代碼來源:delta_ge.c

示例15: main

int main(int argc,char **argv)
{
  FILE *fptr;
  int line_len;
  int line_no;
  int val;
  int max_nonzero_streak;
  int max_nonzero_streak_start_ix;
  int curr_nonzero_streak;
  int curr_nonzero_streak_start_ix;

  if (argc != 2) {
    printf(usage);
    return 1;
  }

  if ((fptr = fopen(argv[1],"r")) == NULL) {
    printf(couldnt_open,argv[1]);
    return 2;
  }

  line_no = 0;
  max_nonzero_streak = 0;
  curr_nonzero_streak = 0;


  for ( ; ; ) {
    GetLine(fptr,line,&line_len,MAX_LINE_LEN);

    if (feof(fptr))
      break;

    sscanf(line,"%d",&val);

    if (!val) {
      if (curr_nonzero_streak > max_nonzero_streak) {
        max_nonzero_streak = curr_nonzero_streak;
        max_nonzero_streak_start_ix = curr_nonzero_streak_start_ix;
      }

      curr_nonzero_streak = 0;
    }
    else {
      if (!curr_nonzero_streak)
        curr_nonzero_streak_start_ix = line_no;

      curr_nonzero_streak++;
    }

    line_no++;
  }

  if (curr_nonzero_streak > max_nonzero_streak) {
    max_nonzero_streak = curr_nonzero_streak;
    max_nonzero_streak_start_ix = curr_nonzero_streak_start_ix;
  }

  fclose(fptr);

  printf("%d (%d)\n",max_nonzero_streak,max_nonzero_streak_start_ix+1);

  return 0;
}
開發者ID:neostreet,項目名稱:command_line_tools,代碼行數:63,代碼來源:max_nonzero_streak.c


注:本文中的GetLine函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。