标签: printf

如何在C中打印没有库函数的变量的charcater,字符串或值?

例如,如果我不应该使用像printf,putchar这样的标准库函数,那么如何轻松地将字符打印到屏幕上.有没有简单的方法来做到这一点.我不太了解系统调用,如果我必须使用它们,那么如何?

那么任何一个建议都可以轻松打印而不使用库函数?

c printing printf character putchar

8
推荐指数
3
解决办法
8098
查看次数

如何使用'printf'打印'%'字符?

我无法弄清楚的简单问题......

如何在printf字符串中打印'%'字符?下面的代码打印出来,但也会出现"无效转换"错误.

printf "\t\t".$hour."00 HRS\t=>\t%.2f\t%.2f\t%.1f\%\n", $total, $max15, ($max15/$total*100);
Run Code Online (Sandbox Code Playgroud)

应输出如下内容:

        0000 HRS    =>    3125.19    898.02    28.7%
Run Code Online (Sandbox Code Playgroud)

perl printf

8
推荐指数
3
解决办法
2万
查看次数

微软_stprintf警告

为什么我收到以下代码的以下警告:)

码:

_stprintf(m_szFileNamePath,_T("%s"),strFileName);
Run Code Online (Sandbox Code Playgroud)

警告C4996:'_ swprintf':swprintf已更改为符合ISO C标准,添加了额外的字符计数参数.要使用传统的Microsoft swprintf,请设置_CRT_NON_CONFORMING_SWPRINTFS.

我知道_strprintf是一个宏,如果定义_UNICODE将评估为_swprintf,否则它将是sprintf.

现在这是什么_swprintf.有一个函数swprintf,但为什么_stprintf评估为_swprintf而不是swprintf.

b/w _xxx和xxx有什么区别?

编辑:

好的,_stprintf的UNICODE版本有两个定义,其中一个包含在内?

tchar.h或strsafe.h中的那个?

c++ printf visual-c++

8
推荐指数
1
解决办法
2万
查看次数

printf太聪明了从char到int?

为什么以下电话:

printf("%d %d", 'a', 'b');
Run Code Online (Sandbox Code Playgroud)

导致"正确" 97 98值?%d表示函数必须读取4个字节的数据,而printf不能告诉接收到的参数的类型(格式字符串除外),为什么不打印数字|a||b||junk||junk|?

提前致谢.

c printf byte casting

8
推荐指数
1
解决办法
9241
查看次数

OCaml中的用户定义的打印机

printf,fprintf等等:都接受%a转换.

手册说%a:

"用户定义的打印机.使用两个参数并将第一个参数应用于outchan(当前输出通道)和第二个参数.因此,第一个参数必须具有类型out_channel - >'b - > unit和第二个'b.因此,函数产生的输出被插入到当前点的fprintf输出中."

我无法理解用户定义的打印机的用途,以及如何实现和使用它.有人可以解释动机并提供一个例子吗?

例如,当您想要打印复杂的数据结构时,为什么不能直接将自定义函数的数据结构打印到字符串或输出?

printf ocaml pretty-print

8
推荐指数
2
解决办法
2939
查看次数

8
推荐指数
2
解决办法
1万
查看次数

c函数返回格式化字符串

我想做这样的事情:

writeLog(printf("This is the error: %s", error));
Run Code Online (Sandbox Code Playgroud)

所以我正在寻找一个返回格式化字符串的函数.

c string printf

8
推荐指数
2
解决办法
5853
查看次数

Shell GNU-Screen -X Stuff问题

OPTIONS="java -Xms1024M -Xmx1024M -jar craftbukkit.jar"
PROCESS=server01

screen -dmS $PROCESS $OPTIONS nogui             # Starting the application
screen -x $PROCESS -X stuff `printf "stop\r"`   # Closing the application
screen -x $PROCESS                              # Attaching to the terminal of the application
Run Code Online (Sandbox Code Playgroud)

应用程序在开始时工作正常,但是我遇到问题stuff 'printf "stop/r"' 当我刚启动时似乎没有工作,等待一段时间然后尝试使用上面的命令停止它.但奇怪的是,如果我这样做screen -x $PROCESS并且分离(ctrl-A & ctrl-D)然后我使用Stop命令它确实有效.那么,有没有办法解决,以stuff printf不screen -x $PROCESS?

linux bash shell printf gnu-screen

8
推荐指数
1
解决办法
3679
查看次数

在C中读取和打印.txt文件行的最清晰方法

有很多方法描述如何使用各种方法在此站点上打印文本文件的行:

它们似乎都是根据具体的例子量身定制的.

如果能够使用最清晰,最简洁,最简单的方法,那就太棒了:将任何文本文件的每一行打印到屏幕上.优选地详细说明每条线的作用.

简洁明了的要点.

c file-io printf scanf file-read

8
推荐指数
1
解决办法
2万
查看次数

如何在C中打印errno的符号名称?

我可以使用perror()或strerror()打印属于a的"人类可读"错误消息errno,但是如果我还要打印符号名称(例如" EAGAIN")的话errno呢?

任何方便的功能或宏来做到这一点?

更新:附上我最终编写的代码,基于下面接受的答案及其评论的想法:

#include <ctype.h>
#include <errno.h>
#include <stdio.h>

int get_errno_name(char *buf, int buf_size) {
    // Using the linux-only gawk instead of awk, because of the convenient
    // match() functionality. For Posix portability, use a different recipe...
    char cmd[] = "e=       && " // errno to be inserted here (max digits = 6)
                 "echo '#include <errno.h>' | "
                 "gcc -dM -E - | " // optionally, use …
Run Code Online (Sandbox Code Playgroud)

c printf errno strerror

8
推荐指数
2
解决办法
4697
查看次数