String Functions

Standard Input/Output
  • String functions

    • String doesn’t provide any operator to manipulate entire string at once
    • Strings are manipulated via functions available from standard string library string.h
    • There are many functions, but the followings are the frequently used ones
  • Character functions

    • There are many functions, but the followings are the frequently used ones
  • StringDemo Source Code

    /*

     * File:   main.c

     * Author: phamvanvung

     *

     * Created on September 21, 2014, 4:55 PM

     */

     

    #include <stdio.h>

    #include <stdlib.h>

    #include <string.h>

    /*

     *

     */

    int main(int argc, char** argv) {

        //"John " -> ASCII table ->

        char firstName[10] = "John";

        char lastName [10] = "Doe";

        char fullName[20];

        strcpy(fullName, firstName);

        strcat(fullName, " ");

        strcat(fullName, lastName);//"John Doe"

        printf("The full name is: %s\n", fullName);

        int ln = strlen(fullName);

        printf("The length of the full name is: %d\n", ln);

        int result = strcmp(firstName, lastName);

        if(result < 0){

            printf("%s is smaller than %s\n", firstName, lastName);

        }else if(result==0){

            printf("%s is equal to %s\n", firstName, lastName);

        }else{

            printf("%s is greater than %s\n", firstName, lastName);

        }

        if(strcmp("34", "123")>0){

            printf("\"34\" is greater than \"123\"");

        }

       

        return (EXIT_SUCCESS);

    }