#include <stdio.h>
FILE * Openfile(char *filename,char *mode, FILE *fp);
int main(){
FILE *fp=NULL;
char *filename = "simple_index.file";
char *openmode = "w";
printf("FP(before call function):%p\n", fp);
FILE *newfp = Openfile(filename, openmode, fp);
printf("FP(after call function): %p\nNEWFP: %p\n", fp, newfp);
return 0;
}
FILE * Openfile(char *filename,char *mode, FILE *fp){
printf((fp = fopen(filename, mode)) ? "Good opening %s file\n": "Error open %s file\n", filename);
return fp;
}
Run Code Online (Sandbox Code Playgroud)
结果:
FP(before call function):0x0
Good opening simple_index.file file
FP(after call function): 0x0
NEWFP: 0x800bc7140
Run Code Online (Sandbox Code Playgroud)
在使用函数打开调用 …
建议使用以下哪项?
printf("DON>");
Run Code Online (Sandbox Code Playgroud)
要么
const char prompt[] = "DON>";
printf("%s", prompt);
Run Code Online (Sandbox Code Playgroud)
有什么不同?
我是新手malloc()
,一直在阅读我的书籍和一些关于它的教程.既然我已经编写了我的作业,那么就要求你没有任何内存泄漏.
这是我的代码的一部分我是如何用main编写的:
#define _CRTDBG_MAP_ALLOC
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <crtdbg.h>
int main()
{
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
srand((unsigned)time(NULL)); //Kallas för randomisera ett nummer tidsmässigt
struct CardDeck * deck; //Dynamiskt allokerad array
int index;
int suit_index;
/*int i; kan användas om man vill loopa kortleken*/
deck = (struct CardDeck *)malloc(sizeof(struct CardDeck)); //Bör bara användas en gång med tanke på att vi bara har en pekare under vår struct i cardeck
deck->last_Index = 0; //Pekar på senaste …
Run Code Online (Sandbox Code Playgroud) 我有以下数组,我想根据嵌套数组中元素数量的降序对其进行排序.
array = [[2], [0,3], [0,1], [1,2,4,5], [1,6,10], [], [7,8], [], [], [8], [9]]
Run Code Online (Sandbox Code Playgroud)
排序后,它应该是这样的
array = [[1,2,4,5], [1,6,10], [0,3], [0,1], [7,8], [8], [9], [2], [], [], []]
Run Code Online (Sandbox Code Playgroud)
我想到计算元素并将其保存在嵌套数组中,但我不知道如何对其进行排序.最终,我希望能够在Ruby中使用msort函数.
例:
int amount = 10050;
printf("format_string", amount);
// What should the format string look like to get $100.50 as the output?
Run Code Online (Sandbox Code Playgroud)
是否有可能告诉printf
函数我想要从右边放两个数字点而不做这样的事情:
int amount = 10050;
printf("$%d.%02d", amount / 100, amount % 100); // Output: $100.50
Run Code Online (Sandbox Code Playgroud) 我一直在努力将标准普尔500指数的价值(现在是1864.78)转换为它在内存中以IEEE单精度格式表示的价值.
转换小数点左边(1864)很容易.
11101001000.
但是如何获得十进制的二进制表示(.78)?我尝试使用该技术但它在8位指数IEEE格式上产生了许多数字:
.78*2 = 1.56 1
.56*2 = 1.12 1
.12*2 = .24 0
.24*2 = .48 0
.48*2 = .96 0
.96*2 = 1.92 1
.92*2 = 1.84 1
.84*2 = 1.68 1
.68*2 = 1.36 1
.36*2 = .72 0
.72*2 = 1.44 1
.44*2 = .88 1(向上舍入,因为现在我们总共有23位)
11101001000.110001111011 =尾数23位
添加0表示符号
0 11101001000.110001111011
现在我需要将小数移动10个以上
1.1101001000110001111011 x 2 ^ 10指数现在是10
添加0位以使全尾数为23位
1.11010010001100011110110
指数是10所以10 + 127 = 137
等于10001001
所以0 10001001 11010010001100011110110是32位数.
这看起来像是一个体面的方法吗?我测试了这个值并写下了这个问题,我实际上可以自己完成它.
用这个测试十进制FP. http://www.h-schmidt.net/FloatConverter/IEEE754.html
I'm getting a bunch of pointer errors and pointers are not exactly my strongest point. Most of my errors have to do with passing an argument.
The errors are:
HW5_mkhan44.c: In function ‘main’: HW5_mkhan44.c:31:3: warning: passing argument 1 of ‘search_and_count’ from incompatible pointer type [enabled by default]
HW5_mkhan44.c:11:6: note: expected ‘struct FILE *’ but argument is of type ‘struct FILE **’
HW5_mkhan44.c:31:3: warning: passing argument 2 of ‘search_and_count’ from incompatible pointer type [enabled by default]
HW5_mkhan44.c:11:6: note: expected ‘const char …
我不知道GCC有哪些可以帮助我的案例?
有效的UTF-8字符(代码点除外0
)是否仍包含零字节?如果是这样,我认为这样的功能strlen
会破坏那个UTF-8字符.
有效的UTF-8字符是否包含一个值等于的字节'\n'
?如果是这样,我认为"获取"等功能将打破UTF-8字符.
有效的UTF-8字符是否包含值等于' '
或等于的字节'\t'
?如果是这样,我认为这样的功能scanf("%s%s")
会破坏UTF-8字符并被解释为两个或更多的单词.
我陷入了书中的问题.问题是 -
典型的互联网新手是一个名字B1FF,他有一种独特的编写消息的方式.这是一个典型的B1FF公报:
H3Y DUD3,C 15 R1LLY C00L
写一个"B1FF过滤器",读取用户输入的消息并翻译它进入B1FF说话:
输入消息:嘿伙计,C很酷,
在B1FF说话:H3Y DUD3,C 15 R1LLY C00L
你的程序应该将消息转换为大写字母,替换某些字母的数字(A = 4,B = 8,E = 3,I = 1,O = 0,S = 5).
我的节目 -
#include<stdio.h>
int main()
{
char arr[50]={0},ch[50]={0};
int i=0;
printf("\nenter the sentence : ");
while(arr[i-1]!='\n')
{
scanf("%c",&arr[i]);
i++;
}
i=0;
while(arr[i]!='\n')
{
if(arr[i]=='e')
ch[i]='3';
if(arr[i]==('A'||'a') )
ch[i]='4';
if(arr[i]==('B'||'b'))
ch[i]='8';
if(arr[i]==('I'||'i'))
ch[i]='1';
if(arr[i]==('o'||'O'))
ch[i]='0';
if(arr[i]==('S'||'s'))
ch[i]='5';
else ch[i]=arr[i]-32;
i++;
}
ch[i]='\n';
i=0;
printf("\nIn B1FF-SPEAK : ");
while(ch[i]!='\n')
{
printf("%c",ch[i]);
i++;
}
printf("\n"); …
Run Code Online (Sandbox Code Playgroud) 我在接受采访时给了我以下代码: -
union mix
{
int i;
char c[2];
};
int main()
{
union mix key;
key.i=512;
printf("\n %d,%d,%d",key.i,key.c[0],key.c[1]);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我回到家并在系统上运行时,我得到了输出: - 512,0,2.
任何人都可以向我解释它是如何工作的或为什么c [1] = 2?
编辑: - 我所知道的是它与内存中的位存储有关.