打印“标签” [英] Printing "tab"
问题描述
我写了一个小小的无关紧要的程序,帮我写一个更多的
重要的!!这应该打印所有的Ascii值从0
到127:
#include< stdio.h>
#define UPPER_LIMT 127
int main(){
int i;
printf("%7s%7s \ n \ n",Decimal,Value);
for(i = 0; i< = UPPER_LIMT; i ++)
printf("%3d%7c \ n",i,i);
返回0;
}
但是,我想看看,例如''TAB''而不是
颠倒问号,十进制值''9'。我可以在printf中使用
转换吗?
提前致谢。
mdh写道:我写了一个微不足道的程序,帮我写一个更重要的一个! !...应该打印从0
到127的所有Ascii值:
>
#include< ; stdio.h>
#define UPPER_LIMT 127
int main(){
int i;
printf("% 7s%7s \ n \\ nn",Decimal,Value);
for(i = 0; i< = UPPER_LIMT; i ++)
printf("%3d% 7c\\\
,i,i);
返回0;
}
>>
然而,我例如,我想看看''TAB'而不是一个颠倒的问号,十进制值''9'。我可以在printf中使用
转换吗?
家庭作业。
提示:考虑一下接受char作为输入并返回
字符指针的函数。
Tom
Tom St Denis写道:提示:考虑一个函数,它接受一个char作为输入并返回一个
字符指针。
oh哦......我在K& R的第77页......迫不及待地想要进入第93页
Pointers and Arrays!!!但是,如果你改变你的提示以避免
指针...我会字节:-)
mdh写道:Tom St Denis写道:提示:考虑一个接受char作为输入并返回
字符指针的函数。 / blockquote>
哦哦....我在K& R的第77页...迫不及待地想要进入第93页
指针和阵列! !但是,如果你改变你的提示以避免
指针...我将字节: - )
然后使用switch或if语句。
if(x ==''\ t'')printf(" tab");
else printf("%c",x);
.....
看,妈,没想到!
Tom
I wrote a little insignificant program, to help me write a more
significant one!!...that was supposed to print all Ascii values from 0
to 127:
#include <stdio.h>
# define UPPER_LIMT 127
int main (){
int i;
printf("%7s%7s\n\n", "Decimal", "Value");
for ( i=0; i<= UPPER_LIMT; i++)
printf( "%3d%7c\n", i, i);
return 0;
}
However, I would like to see, for example, ''TAB'' instead of an
upside-down question mark, at decimal value ''9''. Is there a
conversion I could use for this in printf?
Thanks in advance.
解决方案
mdh wrote:I wrote a little insignificant program, to help me write a more
significant one!!...that was supposed to print all Ascii values from 0
to 127:>
#include <stdio.h>
# define UPPER_LIMT 127
int main (){
int i;
printf("%7s%7s\n\n", "Decimal", "Value");
for ( i=0; i<= UPPER_LIMT; i++)
printf( "%3d%7c\n", i, i);
return 0;
}
>>
However, I would like to see, for example, ''TAB'' instead of an
upside-down question mark, at decimal value ''9''. Is there a
conversion I could use for this in printf?
Homework.
Hint: consider a function which accepts a char as input and returns a
char pointer.
Tom
Tom St Denis wrote:Hint: consider a function which accepts a char as input and returns a
char pointer.
oh oh....I am on page 77 of K&R...can''t wait to get to page 93
"Pointers and Arrays"!!! But, if you change your hint to avoid
pointers...I will byte :-)
mdh wrote:Tom St Denis wrote:Hint: consider a function which accepts a char as input and returns a
char pointer.
oh oh....I am on page 77 of K&R...can''t wait to get to page 93
"Pointers and Arrays"!!! But, if you change your hint to avoid
pointers...I will byte :-)
Use a switch or if statement then.
if (x == ''\t'') printf("tab");
else printf("%c", x);
.....
Look ma, no thought!
Tom
这篇关于打印“标签”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!