String 簡介 mitblog 發表在 痞客邦 留言(0) 人氣(10,269)
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;
}
mitblog 發表在 痞客邦 留言(0) 人氣(295)
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
mitblog 發表在 痞客邦 留言(0) 人氣(94)
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
mitblog 發表在 痞客邦 留言(0) 人氣(233)