我正在尝试打印"你好,数字5是正确的!" 在C.
我现在的方式是使用两个printf语句:
printf("Hello the number %d", number);
printf(" is correct!\n");
Run Code Online (Sandbox Code Playgroud)
如何在Java中的一个语句中执行此操作:
System.out.println("Hello the number "+number+" is correct!");
Run Code Online (Sandbox Code Playgroud)
我试过在C中这样做:
printf("Hello the number %d", number, " is correct!");
Run Code Online (Sandbox Code Playgroud)
但是"是对的!" 没有出现.
有没有办法在一个声明中这样做?对不起,我对C.很新.
我有以下代码:
#include <stdio.h>
#include <string.h>
int main(void)
{
char buff[50];
int pass = 0;
printf("\n Enter the password : \n");
gets(buff);
char str[80];
strcat(str, "nw");
strcat(str, "ww");
strcat(str, "io");
strcat(str, "oi");
char str2[22];
strcat(str2, "jm");
strcat(str2, "qw");
strcat(str2, "ef");
strcat(str2, "io");
strcat(str2, "nw");
strcat(str2, "ce");
strcat(str2, "or");
strcat(str2, "ww");
strcat(str2, "qf");
strcat(str2, "ej");
strcat(str2, "oi");
if(strcmp(buff, str))
{
/* we sf as df er fd xc yyu er we nm hj ui ty as asd qwe er t yu as …Run Code Online (Sandbox Code Playgroud) 这里有一个奇怪的代码:
const double a[] = {0,1,2,3,4};
int main()
{
double *p = a;
printf("%f\n",p[2]); //2.000000
printf("%f\n",p); //2.000000
}
Run Code Online (Sandbox Code Playgroud)
它返回2.000000,为什么?
#include <stdio.h>
int main() {
static int i = 5;
if (--i) {
main();
printf("%d ", i);
}
}
Run Code Online (Sandbox Code Playgroud)
输出是
0 0 0 0
Run Code Online (Sandbox Code Playgroud)
我想知道printf这个程序是如何执行的.
#include<stdio.h>
#include<stdlib.h>
struct Graph
{
int v;
};
int main()
{
struct Graph* graph = (struct Graph*) malloc(sizeof(struct Graph));
graph -> v = 1;
printf("%u", graph);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是我收到有关该行格式的警告:
printf("%u", graph);
Run Code Online (Sandbox Code Playgroud)
警告是:
/home/praveen/Dropbox/algo/c_codes/r_2e/main.c | 14 |警告:格式'%u'期望参数类型为'unsigned int',但是参数2的类型类型为'struct Graph *'[-Wformat =] |
我应该为类型使用什么格式说明符struct Graph *?
为什么第一个printf()只返回值-536870912,第二个返回a的最大值unsigned int与乘以65535*65535的结果之间的差值.(运行64位机器).
int x = 7 * 536870912;
printf("%d\n", x);// 536,870,912
//answer: 3,758,096,384 - 3 Billion
//returns : - 536870912
printf("%d\n", 65535 * 65535 );// 65,535
// answer : 4,294,836,225 4 Billion
// returns: -131071
Run Code Online (Sandbox Code Playgroud) 为什么编译器只为这个错误的程序产生警告而不是错误?
int main(){
int a=3,b=4;
printf("%d,%d");
return 0;
}
Run Code Online (Sandbox Code Playgroud) 基本上,我有以下代码:
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;
int main(void)
{
string energy[9] ={"1E4","3E4","1E5","3E5","1E6","3E6","1E7","3E7","1E8"};
for (int j = 0; j < 9; j++)
{
//printf("%s\n", energy[j]);
//cout << energy[j] << endl;
}
}
Run Code Online (Sandbox Code Playgroud)
我想用printf来“打印”字符串数组的每个元素,就像“ cout”命令一样。我已经尝试过指向数组第一个元素的指针和其他一些技术,但是我无法使其工作。我需要在printf中添加什么,为什么我的printf中当前不可用?
在此先感谢您的帮助。
* p ++通常将1加到指针,然后再引用。但是printf只是在取消引用后才使用该值,而指针先增加后又取消引用。
#include<stdio.h>
int main()
{
int a[] = { 10,20,30 };
int *p = a;
printf("%d\n", *p++);//this makes p point at 20 but prints 10
printf("%d\n", *p);//prints 20
printf("%d\n", a[0]);//prints 10
}
Run Code Online (Sandbox Code Playgroud)
有人可以解释为什么会这样吗?
提前致谢
我正在将数字从10个计数系统(cs)转换为另一个,并将其打印到文件中。
void Fileoutkey(char *res1, char *res2, int sys1, int sys2) //KANON
{
FILE *fp;
if(fp = fopen("task_out.cpp", "w"))
{
fprintf(fp, "%d: %s\n", sys1, res1);
fprintf(fp, "%d: %s\n", sys2, res2);
fclose(fp);
}
else
{
printf("No such file in directory.\n");
exit(1);
}
}
Run Code Online (Sandbox Code Playgroud)
转换功能(可以)
int numSystem1 = 12;
char digits1 [13] = "0123456789AB";
char result1 [18] = "";
int digCount1 = 0;
while (num)
{
int rem1 = num % numSystem1;
result1 [digCount1] = digits1[rem1];
num /= numSystem1;
digCount1++;
for (int i …Run Code Online (Sandbox Code Playgroud)