char *strcat (char targetString[], const char string_toAppend[]);數組
Appends [ə'pend附加] a copy of a source string to the end of a target string, including the terminating ASCII NUL byte. The initial [ɪ'nɪʃəl最初的]character of the string to append[ə'pend附加] overwrites the NUL[空字符] byte[] at the end of the target string. If copying takes place between objects that overlap, the behavior is undefined.app
int sprintf (char targetString[], const char formatString[], ...);函數
Writes output to the specified string according to format specifiers in formatString. A null character is written at the end of the characters written.spa
主要功能是把格式化的數據寫入某個字符串中。 code
#include<stdio.h>
//某個頭文件 intmain()/*主函數「整數」類型*/
{
charbuffer[50]; /* 「字符」類型的數組,下面共有50個元素。*/
int n,a=5,b=3; /* 三個變量都爲「整數」類型*/
n=sprintf(buffer,"%dplus%dis%d",a,b,a+b); /* 賦予數值*/
printf("[%s]isastring%dcharslong\n",buffer,n); /* 「格式輸出」*/
return0; /* 「返回零」 也就是程序正常退出*/
}
[5 plus 3 is 8] is a string 13 chars long
|
strcpy -- 字符串拷貝函數// ----------------------------------------------------------------------------------------------得到文件路徑 int GetIniFilePath(char*filename,char*filepath,char *errmsg) { char CurrentFilePath [1024] ={"\0"}; char FilePathConfFile [1024]={"\0"}; if(GetDir (CurrentFilePath)<0) { return -1; } strcat(CurrentFilePath,"\\Config"); sprintf (FilePathConfFile, "%s\\%s.ini", CurrentFilePath,filename); strcpy(filepath,FilePathConfFile); return 0; }
char *strcpy (char targetString[], const char sourceString[]);orm
Copies a source string including the terminating ASCII NUL byte into a target string. If copying takes place between objects that overlap[əʊvə'læp重疊], the behavior is undefined. 【src和dest所指內存區域不能夠重疊且dest必須有足夠的空間來容納src的字符串】blog