Use user-defined output functions - C String

C examples for String:String Function

Description

Use user-defined output functions

Demo Code

#include <stdio.h>
void put1(const char *);
int put2(const char *);

int main(void){
    put1("test 1");
    put1("test 2,\n");
    printf("I count %d characters.\n", put2("this is a test."));
    return 0;//from  w ww .j a va  2s.c o  m
}

void put1(const char * string){
    while (*string)  /* same as *string != '\0' */
        putchar(*string++);
}

int put2(const char * string){
    int count = 0;
    while (*string){
        putchar(*string++);
        count++;
    }
    putchar('\n');
    
    return(count);
}

Result


Related Tutorials