C语言如何一句多行写呢?如下面例子的最后一句

来源:百度知道 编辑:UC知道 时间:2024/07/06 12:30:17
#include<stdio.h>
main()
{char name[31];
long num;
int eng,math,comp;
float aver;
printf("Please input the student's name:");
scanf("%s",name);
printf("Please input the sudent's ID:");
scanf("%ld",&num);
printf("Please input the scores(English,math,computer):");
scanf("%d %d %d",&eng,&math,&comp);
aver=(eng+math+comp)/3;
printf("The student's name is %s,his ID is %ld,his average score is %.1f\n",name,num,aver);
}
最后一句printf("The student's name is %s,his ID is %ld,his average score is %.1f\n",name,num,aver);
我在"ID is"中间按回车转行时编译出错,在任意两个单词间按回车转行时都出错,加“+”号转行时也出错,请问怎样转行的呢?
谢谢!
我用的编译器是Turbo C 2.0 ,\是对的,不过在TC 2.0中不用引号,在TC2中在两边加上双引号然后回车转行也可以,非常感谢youyuan1688和SinbadLee!
另外我还想问一下在标准教材中是怎样实现任意转行的呢?都有哪样方法呢?
谢谢!

不知到你用的是什么编译器,新的编译器可以在字符串中间断行的,两边都要加上双引号才行,还有楼上的方法也可以试一下\ 这是在定义宏的时候常用的,不过前后的引号要不要还要看你的编译器了。

最后就是既然你用printf分成一部分一部分打印不就行了,只要不打印回车在屏幕上当然是连接在一起的

只要在需要换行的地方添加反斜杠字符就可以续行了。比如:
printf("The student's name is %s,his ID\
is %ld,his average score is %.1f\n",name,num,aver);
请注意:添加的反斜杠字符后面不能有任何字符。

printf("The student's name is %s,his ID" \
" is %ld,his average score is %.1f\n",name,num,aver);
试试