有人可以帮我理解发生了什么吗?
char pcMessage[255];
iMsgAllocatedLength=255;
unsigned long long ullRecordID = 135290303ULL;
sprintf_s(pcMsg, iMsgAllocatedLength, "%08X;%llu", ullRecordID, ullRecordID);
Run Code Online (Sandbox Code Playgroud)
给出以下结果
08105DBF ; 581067426850930688;
而
sprintf_s(pcMsg, iMsgAllocatedLength, "%010llu;%08X;", ullRecordID, ullRecordID);
Run Code Online (Sandbox Code Playgroud)
给出预期的结果
0135290303; 08105DBF
请注意,我只是颠倒了订单,并注意到
581067426850930688是08105DBF 00000000
请帮我理解.
我是C编程的新手,我想弄清楚如何在使用putchar()函数打印int值后添加换行符("\n").在K&R的"The C Programming"一书中,他们提供了下面的脚本,但所有字符都印在同一行上.如何修改代码以每行打印一个字符?
#include <stdio.h>
void main() {
int c;
c = getchar();
while (c != EOF) {
putchar(c);
c = getchar();
}
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用printf()这样的东西:
printf("%d\n", c);
Run Code Online (Sandbox Code Playgroud)
但我想知道C编程和putchar()函数是否有类似的东西:
putchar(str(c)+"\n");
Run Code Online (Sandbox Code Playgroud)
有点像你在python中所做的那样.谢谢!
我无法理解以下代码:
<?php
$number = 123;
vprintf("With 2 decimals: %1\$.2f
<br>With no decimals: %1\$u",array($number));
?>
Run Code Online (Sandbox Code Playgroud)
浏览器输出:
With 2 decimals: 123.00
With no decimals: 123
Run Code Online (Sandbox Code Playgroud)
但是这里只有一个元素在数组中,而它必须是两个参数.
还有什么意思 %1\$
如果ToString是类型中的覆盖
type TestMe ()=
override __.ToString() = null
Run Code Online (Sandbox Code Playgroud)
然后我通过说明"%A"符输出它
printfn "*%A*" (TestMe())
Run Code Online (Sandbox Code Playgroud)
它为什么抛出System.NullReferenceException?
我原以为它会表现得像
printfn "*%A*" null
Run Code Online (Sandbox Code Playgroud)
它只是打印<null>而没有任何例外.
请注意以下终端输出:
$ cat fprintf-closed-file.c
#include <stdio.h>
int main()
{
FILE * ofile = fopen("/tmp/goo", "w");
int success = fprintf(ofile, "Hello %s\n", "World!");
printf("Success: %d\n", success);
fclose(ofile);
success = fprintf(ofile, "Trying again...");
printf("Success: %d\n", success);
}
$ clang -o fprintf-closed-file fprintf-closed-file.c
$ ./fprintf-closed-file
Success: 13
Success: 15
$ cat /tmp/goo
Hello World!
Run Code Online (Sandbox Code Playgroud)
C11标准的第7.21.6.1节说:
fprintf函数将输出写入stream指向的流,在指向格式的字符串的控制下,该格式指定后续参数如何转换为输出.
接下来是转换说明符的描述,但结尾为:
返回
fprintf函数返回传输的字符数,如果发生输出或编码错误,则返回负值.
看来假定文件在第二次fprintf调用时关闭,它应该失败,但事实并非如此.我在Kubuntu Trusty 64位上使用Clang 4.0.1和GCC 4.8.4对此进行了测试.
我对标准的理解是否有缺陷,还是应该提交错误?
请考虑以下代码:
#include <stdio.h>
int main() {
int i = 0;
printf("hello%n%d\n", &i, i);
}
Run Code Online (Sandbox Code Playgroud)
为什么打印hello0而不打印hello5?
我有功课,我必须创建一个C程序,从最小到最大排序5个数字.我知道如何使用函数和if语句(使用>=和<=)轻松编程.
然而,美中不足的是,我只允许使用printf和scanf,所以我必须要计算所有的>=和<=内部的printf.我不允许使用三元运算符.
我一直在努力.所以我试着只排序3个数字,我仍然无法通过排序最小的数字.它只是保持打印1.
// This printf is just trying to figure out the smallest number from 3 numbers provided but it keeps printing 1.
printf("The ascending order of the numbers are: %d ",
(
(num1 <= num2 && num1 <= num3) || // Checking if num1 is the smallest
(num2 <= num1 && num2 <= num3) || // Checking if num2 is …Run Code Online (Sandbox Code Playgroud) 所以我认为我可以打印出这样的内部十六进制float:
const auto foo = 13.0F;
const auto bar = reinterpret_cast<const unsigned char*>(&foo);
printf("0x%02hhX%02hhX%02hhX%02hhX\n", bar[0], bar[1], bar[2], bar[3]);
Run Code Online (Sandbox Code Playgroud)
这输出:
0x00005041
但是当我查看调试器时,它报告的十六进制foo是:
0x003EF830
有人可以帮助我理解为什么这不起作用以及我需要做些什么来使它工作?
我有点像C的初学者,所以请原谅任何粗鲁的错误!
我试图用printf()打印一些格式化的值,但它在输出的中间开始换行,即使没有'\n'!问题出在442行的list_topic函数中.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
typedef struct
{
int t_id;
char t_name[35];
char date_creation[30];
char last_post_date[30];
int sub_users;
int num_posts;
char t_desc[500];
} topic;
typedef struct
{
int u_type;
int t_maxreach;
int u_sub_topic[15];
char u_name[16];
char u_pass[16];
} utilizador;
void instalar();
void menu_inicial();
void menu_admin();
void menu_topic();
void menu_user();
void login();
void options();
void topic_gest();
void user_gest();
void stats();
void new_topic();
void alt_topic();
void rmv_topic();
void list_topic();
void new_user(); …Run Code Online (Sandbox Code Playgroud) printf ×10
c ×6
string ×2
c++ ×1
conditional ×1
cuda ×1
endianness ×1
f# ×1
file-io ×1
hex ×1
ieee-754 ×1
if-statement ×1
php ×1