C++ (Cpp) sprintf Examples

C++ (Cpp) sprintf - 30 examples found. These are the top rated real world C++ (Cpp) examples of sprintf extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
/******************************************************************************

MODULE:  MessageHandler

PURPOSE:  Prints a variable argument list to the terminal and echos
  the message to the log file

RETURN VALUE:
Type = int
Value           Description
-----           -----------
TRUE            Always

HISTORY:
Version  Date   Programmer       Code  Reason
-------  -----  ---------------  ----  -------------------------------------
         03/00  Rob Burrell            Original Development
         01/01  John Rishea            Standardized formatting

NOTES:

******************************************************************************/
int MessageHandler
(
    char *module,	/* I:  module who called us (optional) */
    char *format,	/* I:  format string for the message */
    ...			/* I:  variable argument list */
)

{
    va_list arguments;		/* variable list */

    /* message holders; MAX_MESSAGE_LENGTH defined in shared_resample.h */
    char va_message[MAX_MESSAGE_LENGTH], message[MAX_MESSAGE_LENGTH];

    /* create a message */
    va_start( arguments, format );
    vsprintf( va_message, format, arguments );
    va_end( arguments );

    /* since a module name is optional ... */
    if ( module != NULL )
        sprintf( message, "%s : %s", module, va_message );
    else
        sprintf( message, "%s", va_message );

    fprintf( stdout, "%s\n", message );
    fflush( stdout );
    LogHandler( message );

    return ( TRUE );
}
Example #2
0
/***********************************************************
* Function:
* Description:
* Input:
* Input:
* Output:
* Return:
* Others:
***********************************************************/
void Disp_Idle( void )
{
    char	buf[20];
    float	angle;

    lcd_fill( 0 );

    sprintf( buf, "20%02d/%02d/%02d",
             YEAR( mytime_now ),
             MONTH( mytime_now ),
             DAY( mytime_now ) );

    lcd_text12( 0, 10, (char*)buf, strlen( buf ), LCD_MODE_SET );

    sprintf( buf, "%02d:%02d:%02d",
             HOUR( mytime_now ),
             MINUTE( mytime_now ),
             SEC( mytime_now ) );
    lcd_text12( 0, 20, (char*)buf, strlen( buf ), LCD_MODE_SET );

    sprintf( buf, "%03d", gps_speed );

    angle = gps_cog * 2.0 * 3.14 / 360.0;

    lcd_text12( 90, 12, (char*)buf, strlen( buf ), LCD_MODE_SET );

    lcd_drawline( 106, 16, 106 + cos( angle ), 16 + sin( angle ), LCD_MODE_SET );

    lcd_bitmap( 0, 3, &BMP_gsm_g, LCD_MODE_SET );
    lcd_bitmap( 8, 3, &BMP_gsm_3, LCD_MODE_SET );
    GPSGPRS_Status( );
    lcd_update_all( );
}
Example #3
0
static int
prcalling(char *dest, u_char * p)
{
    int l;
    char *dp = dest;

    p++;
    l = *p++ - 1;
    dp += sprintf(dp, "    octet 3 ");
    dp += prbits(dp, *p, 8, 8);
    *dp++ = '\n';
    if (!(*p & 0x80)) {
        dp += sprintf(dp, "    octet 3a ");
        dp += prbits(dp, *++p, 8, 8);
        *dp++ = '\n';
        l--;
    };
    p++;

    dp += sprintf(dp, "    number digits ");
    while (l--)
        *dp++ = *p++;
    *dp++ = '\n';
    return (dp - dest);
}
Example #4
0
/*---------------------------------------------------------------------------*/
void hxbtos(char *dest, char *data, uint8_t datatype)
{
    struct datetime *dt;
    switch(datatype) {
    case HXB_DTYPE_UNDEFINED:	// "Do nothing" Datatype
        sprintf(dest, "0");		// 0 so the format does not break
        break;
    case HXB_DTYPE_BOOL:
    case HXB_DTYPE_UINT8:
        sprintf(dest, "%u", *(uint8_t*)data);
        break;
    case HXB_DTYPE_UINT32:
    case HXB_DTYPE_TIMESTAMP:
        sprintf(dest, "%u", *(uint32_t*)data);
        break;
    case WS_HXB_DTYPE_UINT16:
        sprintf(dest, "%u", *(uint16_t*)data);
    case HXB_DTYPE_DATETIME:
        dt = (struct datetime*)data;
        sprintf(dest, "%u*%u*%u*%u*%u*%u*%u*", dt->hour, dt->minute, dt->second, dt->day, dt->month, (uint16_t)dt->year, dt->weekday);
        break;
    case HXB_DTYPE_FLOAT:
        dtostrf(*(float*)data, 1, 6, dest);
        uint8_t i;
        for(i = 0; dest[i] != '.';) {
            i++;
        }
        dest[i] = ',';
        break;
    }
}
Example #5
0
int promptPassword() {
    char *pass;
    char buf[MAX_LEN];

    pass = getpass("Enter Password: ");

    if(createUserFlag) {
        sprintf(buf, "NEWPASS %s \r\n\r\n", pass);
    } else {
        sprintf(buf, "PASS %s \r\n\r\n", pass);
    }

    Send(clientfd, buf, MAX_LEN, 0);
    Recv(clientfd, buf, MAX_LEN, 0);

    if(strncmp(buf, "SSAPWEN ", 8) == 0 || strncmp(buf, "SSAP ", 5) == 0) {
        if(strcmp(&buf[strlen(buf)-5], " \r\n\r\n") == 0) {
            return TRUE;
        }
    } else {
        Recv(clientfd, buf, MAX_LEN, 0);
        printLoginLog(auditfd, name, hostname, port, FALSE, "ERR 02 BAD PASSWORD");
    }
    return FALSE;
}
Example #6
0
File: check.cpp Project: hrnn/olymp
void xml_write_test_ans (int i)
{
    if (q[i] == WA_NOT_SQUARE)
    {
        sprintf (buf, "WA");
        sprintf (s, "[Polyomino %03d] Not a square", num[i]);
    }
    else if (q[i] == WA_NOT_SYMMETRIC)
    {
        sprintf (buf, "WA");
        sprintf (s, "[Polyomino %03d] Not symmetric", num[i]);
    }
    else if (q[i] == WA_NOT_CONNECTED)
    {
        sprintf (buf, "WA");
        sprintf (s, "[Polyomino %03d] Not connected", num[i]);
    }
    else if (q[i] == r[i])
    {
        sprintf (buf, "OK");
        sprintf (s, "[Polyomino %03d] Best solution found: %d tiles", num[i], q[i]);
    }
    else
    {
        sprintf (buf, "PC");
        sprintf (s, "[Polyomino %03d] Suboptimal solution found: %d tiles, "
                 "best: %d tiles", num[i], q[i], r[i]);
    }
    fprintf (stderr, "\t\t\t<result number=\"%d\" outcome=\"%s\" pc-type=\"0\" "
             "comment=\"%s\" score=\"%.6lf\" max-score=\"%.6lf\">\n",
             i + 1, buf, s, (double) (sc[i] * mult), (double) (mult));
    fprintf (stderr, "\t\t\t</result>\n");
}