小编ᴜsᴇ*_*sᴇʀ的帖子

如何在JavaDoc中插入创建日期

在JavaDoc中插入类的创建日期的最佳方法是什么?一些例子:

在author标签下面,带有字符串"created on"

/**
 * Class description
 *
 * @author Author Name
 * created on 2015/04/01
 */
public class ClassName() {
...
}
Run Code Online (Sandbox Code Playgroud)

在author标签下面,带有字符串"Date:"

/**
 * Class description
 *
 * @author Author Name
 * Date:   2015/04/01
 */
public class ClassName() {
...
}
Run Code Online (Sandbox Code Playgroud)

使用不存在的@date标记

/**
 * Class description
 *
 * @author Author Name
 * @date   2015/04/01
 */
public class ClassName() {
...
}
Run Code Online (Sandbox Code Playgroud)

其他...

最终,最好的日期格式是什么?

April 1, 2015
2015/04/01
...
Run Code Online (Sandbox Code Playgroud)

java format formatting javadoc

18
推荐指数
1
解决办法
2万
查看次数

文件打开时的错误处理

[问题1]

当我将文件打开到函数中时,通常我会这样做:

int read_file (char *filename)
{
    FILE *fin;

    if ( !(fin = fopen(filename, "r")) )
        return 1;

    /* ... */

    return fclose(fin);
}

int main ()
{
    char filename[100];

    if ( read_file(filename) )
    {
        perror(filename);
        exit(1);
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

通常0返回值是错误(对吗?)然后我可以将以前的代码更改为:

int read_file (char *filename)
{
    FILE *fin;

    if ( !(fin = fopen(filename, "r")) )
        return 0;

    /* ... */

    return !fclose(fin);
}

int main ()
{
    char filename[100];

    if ( !read_file(filename) )
    {
        perror(filename);
        exit(1);
    } …
Run Code Online (Sandbox Code Playgroud)

c error-handling fopen file fclose

5
推荐指数
1
解决办法
1万
查看次数

单身模式:静态还是静态最终?

将Singleton的实例声明为static或更好static final

请参阅以下示例:

static

public class Singleton {

    private static Singleton instance = new Singleton();

    private Singleton() {
    }

    public static Singleton getInstance() {
        return instance;
    }

}
Run Code Online (Sandbox Code Playgroud)

static final

public class Singleton {

    private static final Singleton INSTANCE = new Singleton();

    private Singleton() {
    }

    public static Singleton getInstance() {
        return INSTANCE;
    }

}
Run Code Online (Sandbox Code Playgroud)

java singleton static design-patterns final

5
推荐指数
1
解决办法
1930
查看次数

按价值打电话或按推荐打电话?

在下面的代码中,我向函数传递指针*example[10];或整个数组?

#include <stdio.h>

void function (int **)

int main ()
{
    int *example[10];
    function(example);
    return 0;
}

void function (int *example[10])
{
    /* ... */
    return;
}
Run Code Online (Sandbox Code Playgroud)

以下代码的相同问题:

#include <stdio.h>

struct example
{
    int ex;
};

void function (struct example *)

int main ()
{
    struct example *e;
    function(e);
    return 0;
}

void function (struct example *e)
{
    /* ... */
    return;
}
Run Code Online (Sandbox Code Playgroud)

c struct pointers reference

4
推荐指数
2
解决办法
579
查看次数

Split String方法的奇怪行为

考虑以下简单的代码行:

public class Main {

    public static void main(String[] args) {

        String string = "Lorem,ipsum,dolor,sit,amet";
        String[] strings = string.split(",");

        for (String s : strings) {
            System.out.println(s);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

正如预期的那样,输出如下:

Lorem
ipsum
dolor
sit
amet
Run Code Online (Sandbox Code Playgroud)

现在考虑前面的代码中,我只是把的变化,|:

public class Main {

    public static void main(String[] args) {

        String string = "Lorem|ipsum|dolor|sit|amet";
        String[] strings = string.split("|");

        for (String s : strings) {
            System.out.println(s);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我期待相同的输出,但奇怪的是以下内容:

L
o
r
e
m
|
i
p
s
u
m …
Run Code Online (Sandbox Code Playgroud)

java string split

4
推荐指数
1
解决办法
51
查看次数

Realloc成为一个函数

我的问题是'realloc'.以下代码正常工作(没有警告):

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

int main ()
{
    int num=10;
    int *vet;
    int i;

        for (i=0; i<num; i++)
    {
        /* allocate memory of vet to contains (i+1) int */
        vet = (int*) realloc ( vet, (i+1) * sizeof(int) );

        /* write numbers in the allocated memory */
        vet[i] = 321 + i;
    }

    /* print test, if all works I must see:
    | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | …
Run Code Online (Sandbox Code Playgroud)

c initialization function realloc

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

struct example*e:函数(&e)和函数(e)之间的差异

如果我有struct example *e,那么function(&e)和之间有什么区别function(e)

一个例子.

这是第一个代码:

#include <stdio.h>

struct example
{
    int x;
    int y;
};

void function (struct example **);

int main ()
{
    struct example *e;

    function (&e);

    return 0;
}

void function (struct example **e)
{
    / * ... */
}
Run Code Online (Sandbox Code Playgroud)

这是第二个代码:

#include <stdio.h>

struct example
{
    int x;
    int y;
};

void function (struct example *);

int main ()
{
    struct example *e;

    function (e);

    return 0;
}

void function (struct …
Run Code Online (Sandbox Code Playgroud)

c struct function

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

Realloc和sscanf成为一个函数

我有一个有num行的文件:每行包含一个数字.我想将每个数字保存到矢量中*vet.为什么这段代码不起作用?

Segmentation fault (core dumped)

我认为错误是sscanfsave_numbers功能,但我不知道为什么.

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

/* This function allocate memory
and save numbers into a vector */
int save_numbers (int **vet, int *num)
{
    FILE *fin;
    int i = 0;
    char buff[10];

    if ( !(fin = fopen("numbers.dat", "r")) )
        return 1;

    while ( fgets(buff, sizeof(buff), fin) )
    {
        *vet = (int *) realloc (*vet, (i+1) * sizeof(int) );
        sscanf (buff, "%d", vet[i]);
        i++;
    }

    *num = i; …
Run Code Online (Sandbox Code Playgroud)

c malloc file function realloc

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

而对于:什么是最好的?

如果我可以使用for和while两个循环,我应该选择哪个?

[对于]

int num = 10;
int i;

for (i=0; i<num; i++)
{
    /* ... */
}
Run Code Online (Sandbox Code Playgroud)

[而]

int num = 10;
int i = num;

while ( i-- )
{
    /* ... */
}
Run Code Online (Sandbox Code Playgroud)

c for-loop cycle while-loop

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

在翻转句子时,最后一句话没有反转

我编写了i程序,它将翻转一个句子并将其打印出来.

在这段代码中,我得到的所有单词都是正确的,除了最后一个.即在反转代码中的句子之后,"hiii"仍然是"iiih",其余的输出是正确的.

void reverse(char * s, int len){
    int counter = 0;
    int end = len - 1;
    char temp;

    for (counter = 0; counter < len / 2; counter++, end--) {
        temp = s[counter];
        s[counter] = s[end];
        s[end] = temp;
    }
}

int main(void){
    char s[] = "hiii all i want to reverse this sentence so please help me fast";
    int c = 0;
    int len = strlen(s);
    int wl = 0;
    int start = 0;
    printf("\n    s = …
Run Code Online (Sandbox Code Playgroud)

c string algorithm

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