printf-C中字符串和int的连接

printf-C中字符串和int的连接,c,printf,C,Printf,我有以下代码: #define ERROR_MSG "Error: there was an error " #define IN_LINE_MSG "in line" int line = 0; 如何使用printf连接这3个文件,以便打印以下内容: "Error: there was an error in line 0" 查看printf 应该是这样的:printf(“%s%s%d”,错误消息,在第行消息中) 这里,%s代表字符串,%d代表数字。然后,按顺序传入字符串后的这三个参数以代

我有以下代码:

#define ERROR_MSG "Error: there was an error "
#define IN_LINE_MSG "in line"
int line = 0;
如何使用
printf
连接这3个文件,以便打印以下内容:

"Error: there was an error in line 0"
查看
printf

应该是这样的:
printf(“%s%s%d”,错误消息,在第行消息中)

这里,
%s
代表字符串,
%d
代表数字。然后,按顺序传入字符串后的这三个参数以代替这些说明符

printf(ERROR_MSG IN_LINE_MSG " %d", line);


您的意思是类似于
printf(第行错误消息“%d”,第行)
?您想知道如何使用printf打印整数和字符串吗?你试过什么?顺便说一句,你最喜欢的C编程书的第一章非常好。
#include <stdio.h>

#define ERROR_MSG "Error: there was an error "
#define IN_LINE_MSG "in line"
int line = 0;

int main()
{
   printf("%s%s %d", ERROR_MSG, IN_LINE_MSG, line);
}
Error: there was an error in line 0
#include <stdio.h>

#define ERROR_MSG "Error: there was an error "
#define IN_LINE_MSG "in line"
int line = 0;

int main()
{
   printf(ERROR_MSG IN_LINE_MSG " %d", line);
}
Error: there was an error in line 0