Sponsored Links
目前分類:C/C++ 字串函數(string.h) (5)
- Nov 13 Sun 2016 21:37
[C/C++] String 用法
- Mar 06 Wed 2013 14:30
int strncmp(const char* cs, const char* ct, size_t n)
- 這篇文章限定好友觀看。
若您是好友,登入後即可閱讀。
- Dec 16 Sun 2012 20:22
int strcmp(const char* cs, const char* ct)
Example Source Code:strcmp(參數1,參數2),字串參數1與字串參數2 比較。
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
char s[]="abc";
char s2[]="abc";
if(strcmp(s,s2) == 0 )
{
printf("true\n");
}
else
{
printf("false\n");
}
return 0;
}
- Dec 03 Mon 2012 22:03
char* strncpy(char* s, const char* ct, size_t n)
Example Source Code:strncpy(參數1,參數2,參數3),指定參數3長度,參數2 複製到 參數1。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
char strncpy_a[5]={'a','b','c','d','\0'};
char strncpy_b[5];
strncpy_b[2]=0x00;
strncpy(strncpy_b,strncpy_a,2);
printf("%s",strncpy_b);
return 0;
}
//Answer:
//ab
- Dec 03 Mon 2012 20:59
char* strcpy(char* s, const char* ct)
Example Source Code:strcpy(參數1,參數2),將參數2 複製到 參數1。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
char strcpy_a[5]={'a','b','c','d','\0'};
char strcpy_b[5];
strcpy(strcpy_b,strcpy_a);
printf("%s",strcpy_b);
return 0;
}
//Answer:
//abcd
