标签: printf

使用sprintf的这个Perl代码的C++等价物是什么?

我需要模仿以下Perl代码的功能

if($file =~ /^([^_]+)_([^_]+)_MA_(\d{4})(\d\d)(\d\d)_(\d\d)(\d\d)(\d\d)\.MA$/) {
  my ($radar, $beam, $year, $month, $day, $hour, $min, $sec) =
      ($1, $2, $3, $4, $5, $6, $7, $8);
  my $file_ts = sprintf("%04d-%02d-%02d %02d:%02d:%02d",
      $year, $month, $day, $hour, $min, $sec);

  # ...
}
Run Code Online (Sandbox Code Playgroud)

在C++中.我使用哪种功能?

c++ perl printf

-2
推荐指数
1
解决办法
180
查看次数

在C中格式化浮点数

可能重复:
避免在printf()中尾随零

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    int main(void)
    {
      FILE *file;
      double n;  
      file = fopen("fp.source", "r");
      while(!feof(file)) {
        fscanf(file, "%lf", &n);
        printf("Next double:\"%lf\"\n", n); 
    }
    fclose(file);
    return 0;
    }
Run Code Online (Sandbox Code Playgroud)

嗨,我正在尝试扫描浮点数,我已经让它工作,但我得到了我不想要的尾随零.有办法避免这种情况吗?例如,我得到的当前输出是:下一个双倍:"11.540000"

实际上我想:下一个双:"11.54"

c printf

-2
推荐指数
1
解决办法
8218
查看次数

如何在printf"%s \n"10000中显示点?

我有命令printf "%s\n".我希望该命令可以用point(.000)分隔为零.

例如:

printf "%s\n" 300.77

300.77

我想要

printf "%s\n" 1000000

1.000.000

你能帮帮我解决我的问题吗?

bash printf

-2
推荐指数
1
解决办法
162
查看次数

如何在C中使用printf打印出以下值?

我有一个变量:

int a = 0x0304;
Run Code Online (Sandbox Code Playgroud)

我打印出来像这样:

printf("the value is 0x4x\n", a);
Run Code Online (Sandbox Code Playgroud)

但它显示的值是0x304,我想要的结果应该是值0x0304,如何将其打印出来?

c printf

-2
推荐指数
1
解决办法
110
查看次数

十六进制的无符号长整数的值是多少

我有这个变量

unsigned long long latitude = 29.47667;
Run Code Online (Sandbox Code Playgroud)

当我将此值转换为这样的数组时

    ar[7] = (uint8_t)((latitude >> 56) & 0xFF);
    ar[6] = (uint8_t)((latitude >> 48) & 0xFF);
    ar[5] = (uint8_t)((latitude >> 40) & 0xFF);
    ar[4] = (uint8_t)((latitude >> 32) & 0xFF);
    ar[3] = (uint8_t)((latitude >> 24) & 0xFF);
    ar[2] = (uint8_t)((latitude >> 16) & 0xFF);
    ar[1] = (uint8_t)((latitude >> 8) & 0xFF);
    ar[0] = (uint8_t)(latitude & 0xFF);
Run Code Online (Sandbox Code Playgroud)

然后使用tcp socket将其发送到服务器.当我发送时,我以十六进制打印值,然后我0x1d全部休息.

如何在将unsigned long long转换为int时将确切的值发送到服务器.

c embedded floating-point printf

-2
推荐指数
1
解决办法
585
查看次数

为什么printf不在这里打印?

我知道执行后的printf返回一些非零值{编辑:返回否.charecters}现在在这个例子中我使用了多个printf和现在.

 /* As far as i was cocerned Precedence of && is more than ||,
  *and these logical operators check from left to right  
  *So compiler should come to hello and print "hello" then "nice to see you" then "hie" 
  *as all are true it should print "hola" 
  *but i wonder, why here the output is only "hie" and "hola"?
  */  

 #include<stdio.h>
 main()
 {
    if(printf("hie")|| printf("hello")&& printf("nice to see you"))
    printf("\thola\n");
 }
Run Code Online (Sandbox Code Playgroud)

c c++ printf

-2
推荐指数
1
解决办法
171
查看次数

询问用户他们的姓氏和名字,并输入一个电子邮件作为输出

#include <stdio.h>

int main(){

    char last[20];
    char first[20];

    printf("Please enter your last name:");
    scanf("%s",last);
    printf("\nPlease enter your first name:");
    scanf("%s",first);
    printf("Here your email address\n",last,first,@student.com); //last first@student.com

}
Run Code Online (Sandbox Code Playgroud)

我希望用户写下他们的名字,我会自动输出他们的电子邮件.

c printf

-2
推荐指数
1
解决办法
2232
查看次数

以下C程序的输出应该是3,但我得到0为什么?

main()
{
printf ("%d",(3.0/2)*2) ;
}
Run Code Online (Sandbox Code Playgroud)

以下C程序的输出应为3.为什么我得到0?

c printf

-2
推荐指数
1
解决办法
71
查看次数

表示长双值

我想知道如何在long double中重新创建一个值.是L还是LF.我问这个,因为在某些地方我读过它是L和一些LF.在其中一个考试答案和一些像indiabix这样的网站中它是L并且在一些堆栈溢出帖子中它的LF.

c printf floating-point-precision

-2
推荐指数
1
解决办法
193
查看次数

写入文件时fprintf不像printf吗?

我查看了文档:

在这里说:

成功打开文件后,您可以使用fscanf()从中读取文件或使用fprintf()写入文件.这些函数就像scanf()和printf()一样工作,除了它们需要一个额外的第一个参数,一个FILE*用于读/写文件.

所以,我这样编写了我的代码,并确保包含一个条件语句以确保文件打开:

# include<stdio.h>
# include<stdlib.h>

void from_user(int*b){

    b = malloc(10);
    printf("please give me an integer");
    scanf("%d",&b);

}

void main(){

    FILE *fp;

    int*ch = NULL;
    from_user(ch);
    fp = fopen("bfile.txt","w");

    if (fp == NULL){
        printf("the file did not open");
    }
    else {
        printf("this is what you entered %d",*ch);
        fprintf(fp,"%d",*ch);  
        fclose(fp);
        free(ch);   
    }
}
Run Code Online (Sandbox Code Playgroud)

我错了还是文档没有正确解释?谢谢.

c c++ linux file-io printf

-2
推荐指数
1
解决办法
458
查看次数