c语言字符串概念问题????

来源:百度知道 编辑:UC知道 时间:2024/05/09 20:29:41
vb中有强制链接符&,可以把变量和字符串配合起来用.
比如.i=2;
INPUTBOX("D:\"& i & ".jpg")
我想请问C语言中有没有这种功能怎么实现?
当然我不是用来输出时用的.
我想问你那如果我想把一个整形变量和字符串连起来有没有什么方法?????????????

#include <stdio.h>
#include <string.h>

int main(int argc, char* argv[])
{
int n = 235234;
char s[100], temp[100];

strcpy (s, "wgsvafaefa");

sprintf(temp, "%d", n);

strcat(s, temp);

printf("%s", s);

return 0;
}

strcat()可以将两个字符串连接起来,该函数的声明位于string.h中,原型为:

char *strcat(char *s1,const char *s2);

连接s1和s2,并将结果保存在s1中,返回值为s1。

可以用sprintf(char *, const char *fmt,...)函数

其中格式部分与printf()相似

#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[])
{
int n = 235234;
char s[100], temp[100]="wgsvafaefa";
sprintf(s, "%s%d", temp, n);
printf("%s", s);
return 0;
}

就是用sprintf(char *, const char *fmt,...)函数,其功能强大,可以找下相关资料看看。