如何添加换行符 [英] How To Add Line Breaks

查看:94
本文介绍了如何添加换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要添加中断,以便此数据转储不会全部混杂在一起.我如何逐行制作此打印?

I need to add breaks so that this data dump is not all jumbled together. How would I make this print line by line?

void printRawData(unsigned char *data, int length, int more)
{
	int i, c=0;
	printf("     -------------Data Begins-------------\n");
	for (i=0; i<length;>	{
		if ((data[i]>30 && data[i]<122) || 
			(((data[i]==10) || (data[i]==13) || (data[i]==123) || (data[i]==125))
            && (more>0)))
		{
			printf("%c", data[i]);
			c+=1;
                }
		else
		{
			printf("[%i]", data[i]);
			c+=3;
			if (data[i]>9) c++;
			if (data[i]>99) c++;
                }
		if (c>=47)
		{
			printf("\n");
			c=0;
                }
       }
}

推荐答案

换行符是取决于系统的一对字符组合中的一个字符.例如,Microsoft系统使用CR + LF,即0x13,后跟0x10.并非所有Windows组件都需要此确切顺序来显示新行.在C ++中,使用转义序列( http://en. wikipedia.org/wiki/Escape_sequence [ ^ ])) .

对于其他系统,请参见 http://en.wikipedia.org/wiki/End-of-line [ ^ ].请注意,C ++的"\ n"(换行符)和"\ r"(回车符)不需要等同于ASCII LF和CR控制字符.请仔细阅读本文以获取详细信息.

—SA
New line is one character of a combination of pair of characters which is system-dependent. For example, Microsoft system use CR+LF, that is 0x13 followed by 0x10. Not all Windows components require this exact sequence to show a new line. In C++, it looks like "\r\n\", with the use of escape sequences (http://en.wikipedia.org/wiki/Escape_sequence[^]).

For other systems, see http://en.wikipedia.org/wiki/End-of-line[^]. Pay attention that C++ ''\n'' (newline) and ''\r'' (carriage return) are not required to be equivalent to ASCII LF and CR control characters. Read this article carefully to get the detail.

—SA


这篇关于如何添加换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆