标签: printf

C++打印奇怪的表现

我有一个C++问题:

#include<iostream>
#include<stdio.h>

using namespace std;

int main() {
    double k = 1.2366;
    cout << printf("%.3lf\n", k);
}
Run Code Online (Sandbox Code Playgroud)

输出是:

1.237
6
Run Code Online (Sandbox Code Playgroud)

但我希望:

1.237
Run Code Online (Sandbox Code Playgroud)

为什么我在第二行获得额外的6?

c++ printf

-3
推荐指数
1
解决办法
103
查看次数

在C中printf()的意外行为

#include <stdio.h>

int main()
{
    short int a = 5;
    printf("%d" + 1, a);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

printf无论变量的值和类型如何,代码都会打印括在引号中的字母a.如果添加任何其他数字,除了1没有打印.为什么会这样?

c printf

-3
推荐指数
1
解决办法
258
查看次数

在c编程方面需要帮助

我对以下程序有疑问,我无法理解以下程序的输出:

#include<stdio.h>
#include<conio.h>
main()
{
    char c='1';
    clrscr();
    printf("%d",&c);
    getch();
}
Run Code Online (Sandbox Code Playgroud)

在我的编译器中,它打印"-11",我正在使用Turbo C++.我知道,如果我使用" c"而不是" &c"它将打印49因为它是一个ASCII数字'1'.但它为什么打印 - 11当我使用" &c"时.

c printf

-3
推荐指数
1
解决办法
120
查看次数

当sprintf在linux上用python2列入字符串时输入错误

当sprintf在linux上用python2列入字符串时输入错误

x = [ 'aa', 'bbbb', 'ccccccc' ]
f = '%-10s%-10s%-10s'
s = f % x
Run Code Online (Sandbox Code Playgroud)

TypeError:格式字符串的参数不足

python printf

-3
推荐指数
1
解决办法
123
查看次数

为什么文件仅包含第一次迭代的打印

我在C中编写了这个代码,一个接一个地在一个txt文件中打印1到10的nos但是在执行之后只有第一个no打印在txt文件中.请帮助

 #include<stdio.h>
 #include<stdlib.h>
 int main()
 {
     int i;
     FILE *fptr;

     fptr=fopen("C:\\program.txt","w");

     for(i=1;i<=10;i++)
     {
         fprintf(fptr,"\n%d\n",i);
         fclose(fptr);
     }
 }
Run Code Online (Sandbox Code Playgroud)

c file-io printf loops

-3
推荐指数
1
解决办法
48
查看次数

c编程,为什么printf不工作?

#include<stdio.h>

int main(void)  {
  char op;
  int arr[3];
  printf("input ");
  scanf("%d %c %d", arr,&op,arr+1);  
  arr[3]=arr[0]-arr[1]; //here
  printf("[%c] %d\n", op, arr[3]); 
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

arr [3] = arr [0] -arr 1 ; printf("[%c]%d \n",op,arr [3]);

为什么不打印%c?

在此输入图像描述

c printf char

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

C程序提供意外的输出

这是我的C程序:

#include <stdio.h>
main(){ printf("%f", 5/3); }
Run Code Online (Sandbox Code Playgroud)

我期待输出1.000000,但我得到的输出是0.000000.有人可以解释原因吗?

c floating-point printf integer rounding

-3
推荐指数
1
解决办法
60
查看次数

Printf在AJAX php文件中不起作用?

嗨我想通过在html和AJAX技术中使用表单来更新我的mysql数据库中的一些数据.我有问题,因为点击提交后数据没有更新,在响应消息中我不仅有消息,而且还有明确的mysql请求!我们来看看我的警报: 在此输入图像描述

我的想法是printf并不是真正将文本发布到"查询"函数中,但是这个文本输出直接进入响应数据并且查询总是错误的空文本...

我们来看看我的AJAX php文件:

<?php
	session_start();
	error_reporting(0);
	$imie = $_POST['imie'];
	$nazwisko = $_POST['nazwisko'];
	$kodpocztowy = $_POST['kodpocztowy'];
	$ulica = $_POST['ulica'];
	$nrdomu = $_POST['nrdomu'];
	$nrmieszkania = $_POST['nrmieszkania'];
	$miasto = $_POST['miasto'];

	try
	{
		if (! @include_once('connect.php'))
  		throw new Exception ('connect.php kurwa nie istnieje</br>');
		if (!file_exists('connect.php' ))
  		throw new Exception ('connect.php nie istnieje</br>');
		else
  		require_once('connect.php'); 
	}
	catch(Exception $e)
	{    
  		echo "Wiadomo??: " . $e->getMessage();
  		echo "Kod: " . $e->getCode();
	}
	require_once "connect.php";

	$polaczenie = @new mysqli($host, $db_user, $db_password, $db_name);
	if($rezultat = @$polaczenie->query(printf("UPDATE adresy SET …
Run Code Online (Sandbox Code Playgroud)

php mysql ajax printf

-3
推荐指数
1
解决办法
214
查看次数

我无法访问数组内部结构

我修好了它!

  typedef struct student
{
char id[11];
}Student;

 #include<stdio.h>
 #include<stdlib.h>
 int main(int argc, char **argv){
 int input = 0, i = 0;
 FILE * fp = fopen("student.txt", "wt");

if (fp == NULL) {
    printf("Error to open student.txt");
    return -1;
}
 scanf("%d",&input);

 student = (Student *)malloc(input*sizeof(Student));

      for(i=0;i<input;i++){
      strcpy(student[i].id, "a"); // A is just for default. 
      fprintf(fp,"%s\n",student[i].id);
 }
 fclose(fp);
 return 0;
 }          
Run Code Online (Sandbox Code Playgroud)

我已经修改了评论和善意的答案.它确实有效

感谢帮助

我真的很感激!这真的很有用.

c printf struct

-3
推荐指数
1
解决办法
59
查看次数

c ++ cout打印错误的值

我试图建立一个printf功能C++; 它的工作,但是当我打印intfloat,我得到一个0任意值I输入.

#include <iostream>
#include <stdarg.h>

using namespace std;

void printf1(const char* varlist, ...)
{
int i = 0;
va_list Paramters;
va_start(Paramters, varlist);
while (varlist[i] != '\0')
{
    if (varlist[i] == '%')
    {
        switch (varlist[i + 1])
        {
        case 's':
            cout << va_arg(Paramters, const char*);
            cout << ' ';
            break;
        case 'i':
            cout << va_arg(Paramters, int);
            cout << ' ';
            break;
        case 'f':
            cout << va_arg(Paramters, float);
            cout << ' …
Run Code Online (Sandbox Code Playgroud)

c++ printf cout

-3
推荐指数
1
解决办法
607
查看次数

标签 统计

printf ×10

c ×6

c++ ×2

ajax ×1

char ×1

cout ×1

file-io ×1

floating-point ×1

integer ×1

loops ×1

mysql ×1

php ×1

python ×1

rounding ×1

struct ×1