본문 바로가기

C Programing

string functions and operations


 man string.h 명령어를 사용하여 함수에 대한 내용을 검색.


[leechul@~/C_Study]leechul vi 016-string-functions-and-operations.c

#include <stdio.h>

#include <string.h>


int main(int argc, char *argv[])

{

    char str[24];

    char str2[24];

    int i;


    int n;


    /* Example 1 */

    sprintf(str, "Hello World!");

    printf("%s\n",str);


    /* Example 2 */

    i = 4;

    sprintf(str, "Value of i = %d", i);

    printf("%s\n",str);

   

    /* Example 3 */

    n = strlen(str);

    printf("length of str is %d\n", n);


    /* Example 4 */

    strcpy (str2, str);

    printf("str = %s\n",str);

    printf("str2 = %s\n", str2);


    /*Example 5 */

    memset(str, 0, 24);

    printf(">%s<\n", str);


    memset(str, 'a', 5);

    printf(">%s<\n", str);

    

    return 0;

}   





 [leechul@leechul C_Study]$ gcc 016-string-functions-and-operations.c -o 016-string-functions-and-operations.o


[leechul@leechul C_Study]$ ./016-string-functions-and-operations.o 

Hello World!

Value of i = 4

length of str is 14

str = Value of i = 4

str2 = Value of i = 4

><

>aaaaa<


'C Programing' 카테고리의 다른 글

BITWISE OPERAT ORS  (0) 2013.12.31
if(0) and if(!0)  (0) 2013.12.17
multiple-source-files  (0) 2013.12.08
typedef  (0) 2013.12.08
main function arguments  (0) 2013.12.08