基本上我想解码给定的Html文档,并替换所有特殊字符,例如" "- > " ",">"- > ">".
在.NET中我们可以使用HttpUtility.HtmlDecode.
什么是Java中的等效函数?
我正在设计一个实体类,它有一个名为"documentYear"的字段,可能有无符号整数值,如1999,2006等.同时,这个字段也可能是"未知",也就是说,不确定文档是哪一年创建.
因此,C#中的可空int类型将非常适合.但是,Java没有像C#那样可以为空的特性.
我有两个选择,但我不喜欢它们:
java.lang.Integer而不是原始类型int;有没有人有更好的选择或想法?
更新:我的实体类将有数万个实例; 因此,java.lang.Integer的开销可能对系统的整体性能来说太重了.
在整数溢出的情况下,结果是(unsigned int) * (int)什么?unsigned还是int?什么类型确实数组索引运算符(operator[])承担char*:int,unsigned int或其他什么东西?
我正在审核以下功能,突然出现了这个问题.该功能在第17行有一个漏洞.
// Create a character array and initialize it with init[]
// repeatedly. The size of this character array is specified by
// w*h.
char *function4(unsigned int w, unsigned int h, char *init)
{
char *buf;
int i;
if (w*h > 4096)
return (NULL);
buf = (char *)malloc(4096+1);
if (!buf)
return (NULL);
for (i=0; i<h; i++)
memcpy(&buf[i*w], init, w); // line …Run Code Online (Sandbox Code Playgroud) 我正在阅读Microsoft的CRT源代码,我可以提出以下代码,其中函数__initstdio1将在main()例程之前执行.
问题是,如何在VC(不是VC++代码)中输入main()例程之前执行一些代码?
#include <stdio.h>
#pragma section(".CRT$XIC",long,read)
int __cdecl __initstdio1(void);
#define _CRTALLOC(x) __declspec(allocate(x))
_CRTALLOC(".CRT$XIC") static pinit = __initstdio1;
int z = 1;
int __cdecl __initstdio1(void) {
z = 10;
return 0;
}
int main(void) {
printf("Some code before main!\n");
printf("z = %d\n", z);
printf("End!\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出将是:
Some code before main!
z = 10
End!
Run Code Online (Sandbox Code Playgroud)
但是,我无法理解代码.
我在.CRT $ XIC上做了一些谷歌,但没有找到运气.有些专家可以向我解释上面的代码段,尤其是以下内容:
_CRTALLOC(".CRT$XIC") static pinit = __initstdio1;是什么意思?变量pinit有什么意义?Microsoft(R)32位C/C++优化编译器版本15.00.30729.01 for 80x86版权所有(C)Microsoft Corporation.版权所有.
stdmacro.c
stdmacro.c(9) : warning C4047: 'initializing' : 'int' differs …Run Code Online (Sandbox Code Playgroud) 我目前正在写一个C(不是C++).似乎Microsoft的C编译器要求在函数之上声明所有变量.
例如,以下代码不会通过编译:
int foo(int x) {
assert(x != 0);
int y = 2 * x;
return y;
}
Run Code Online (Sandbox Code Playgroud)
编译器在第三行报告错误,说
error C2143: syntax error : missing ';' before 'type'
Run Code Online (Sandbox Code Playgroud)
如果代码更改为如下所示,它将通过编译:
int foo(int x) {
int y;
assert(x != 0);
y = 2 * x;
return y;
}
Run Code Online (Sandbox Code Playgroud)
如果我将源文件名更改.c为.cpp,则编译也将通过.
我怀疑有一个选项可以关闭编译器的严格性,但我还没有找到它.任何人都可以帮忙吗?
提前致谢.
我正在使用Visual Studio 2008 SP1附带的cl.exe.
添加:
谢谢大家回答!看来我必须使用微软的cl.exe生活在C89中.
基本上,我想知道其中的差别之间
Int32^ i = gcnew Int32();
和
Int32* i2 = new Int32();
我写了以下代码:
#include <stdio.h>
#using <mscorlib.dll>
using namespace System;
int main(void) {
Int32^ i = gcnew Int32();
Int32* i2 = new Int32();
printf("%p %d\n", i2, *i2);
printf("%p %d\n", i, *i);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它给出了以下输出:
004158B8 0
00E1002C 0
Run Code Online (Sandbox Code Playgroud)
似乎两个整数分配在两个不同的内存位置.
是否在托管堆中分配了gcnew Int32()?还是直接在堆栈上?
该程序需要输入任意大的无符号整数,该整数在基数10中表示为一个字符串.输出是表示基数16中的整数的另一个字符串.
例如,输入为"1234567890987654321234567890987654321234567890987654321",输出为"CE3B5A137DD015278E09864703E4FF9952FF6B62C1CB1"
算法越快越好.
如果输入限制在32位或64位整数范围内,那将非常容易; 例如,以下代码可以进行转换:
#define MAX_BUFFER 16
char hex[] = "0123456789ABCDEF";
char* dec2hex(unsigned input) {
char buff[MAX_BUFFER];
int i = 0, j = 0;
char* output;
if (input == 0) {
buff[0] = hex[0];
i = 1;
} else {
while (input) {
buff[i++] = hex[input % 16];
input = input / 16;
}
}
output = malloc((i + 1) * sizeof(char));
if (!output)
return NULL;
while (i > 0) {
output[j++] = buff[--i];
}
output[j] = '\0';
return …Run Code Online (Sandbox Code Playgroud) 我有以下两种结构:
问题是sizeof(内容)返回160.结构由11个短路,6个整数,76个字符,7个浮点数,1个双精度数组成,总共增加到158个字节.我已计数三次,仍有2个字节的差异.
typedef struct TIME_T {
short year,mon,day;
short hour,min,sec;
} TIME;
typedef struct {
int no;
char name[20];
char Code[10];
char DASType[10];
short wlen;
float VLtd;
int samp;
int comp;
int locationID;
short TranMode;
char TranIns[12];
short TimerMode;
char ClkType[12];
float ClkErr;
float lat;
float lon;
float alt;
float azimuth,incident;
short weight;
short veloc;
int oritype;
char seismometer[12];
double sens;
TIME start_time;
int record_samples;
} Content;
Run Code Online (Sandbox Code Playgroud)
我写了一小段代码来打印结构中每个变量的位置,然后突然发现float wlen需要4个字节.我的代码如下:
int main(void)
{
Content content;
printf("Sizeof Content: %d\n", sizeof(content)); …Run Code Online (Sandbox Code Playgroud)