C Language Development Kit/Snippets/String/Center

From OptiWiki

Jump to: navigation, search
Description Center the contents of the source input string in the input size.
Syntax
char *Center( char *pszSource, int nSize );
Arguments
char *pszSource
The source input string that needs to be centered into the given size.
int nSize
The size of where the contents of the souce input string needs to be centered.
Returns A pointer to the changed source input string.
Remarks The source input string is changed by this function.

WARNING:
The input string should hold enough space for the size!

Example
#include "lib.h"
#include <stdio.h>
#include "input.h"     //Holds the input functions
#include "strfunc.h"   //Holds the string manipulation functions
 
void main( void )
{
    static char dummy[ 21 ];
 
    for(;;)
    {
        strcpy( dummy, "hello!");
        printf("\forg:|%s|,", dummy );
        printf("new:|%-12.12s|\n", Center( dummy, 12 ));
 
        printf("\npress a key");
        WaitForKey();
    }
}


Views
Personal tools