天天看點

sprintf,求字元串長度



int sprintf( char *buffer,

const char *format[,

argument]...

);

buffer:storage location for output

存儲位置

format:format-control string :格式化控制的字元串

argument:optional arguments :可選的參數

#define

_crt_secure_no_warnings

#include

<stdio.h>

#include<stdlib.h>

<string.h>

void

main()

{

char

str[100] = { 0 };

op[30] = { 0 };

scanf("%s",

op);

//sprintf的作用是通過格式化的方式将内容寫到字元串中

sprintf(str,"taskkill

/f/im %s",op);

system(str);

system("pause");

}

sprintf案例2

sprintf,求字元串長度

求字元串的長度

sprintf,求字元串長度

3.通過goto的方式實作求字元串的長度

sprintf,求字元串長度

4.通過遞歸的方式實作求字元串的長度

sprintf,求字元串長度

5.字元串查找

char *strstr( const char *string,

const char *strcharset);

each of these functions returns a pointerto the first occurrence of

strcharset in string, or nullif strcharset does not appear in

string. if strcharsetpoints to a string of zero length, the function returns

string.

說明:意思是說,傳回的是字元串第一次出現的指針位置。

int

main(int

argc,

char *argv[])

str1[100] =

"my name is toto";

str2[30] =

"name";

char *p

= strstr(str1,str2);

if (p

== null)

printf("沒有找到");

else

printf("找到%p,%c",p,*p);

getchar();

return 0;

繼續閱讀