2

ああ!コンパイラが文句を言うのはなぜですか? 助けてくれてありがとう!

% gcc -o mine mine.c -lcrypt
mine.c: In function 'main':
mine.c:19:14: warning: assignment makes pointer from integer without a cast [enabled by default]
%

コード:

#define _X_OPEN_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main() {

    const char key[] = "hello world";
    const char salt[]="01";
    const int MAXIMUM_HASH_LENGTH = 2 + 11;
    int i=0;

    char *hash;

    long long hashes = 0L;

    while (1) {

        hash = crypt(key, salt); /* problem with this line... */
        if (hash[2] == '0') {
            int leading0s = 0;
            leading0s++;
            for (i=3; i < MAXIMUM_HASH_LENGTH; i++) {
                if (hash[i] != '0') break;

                leading0s++;
            }
            printf("Winner: %s has %d leading zeros.\n",
                    hash, leading0s);
            printf("\t--> Hash %lld.\n\n", hashes);
        }

        if (hashes != 0 && (hashes % 10000) == 0) {
            printf("Hash %d: %s\n", hashes, hash);
        }

        if (hashes== 1000000) break;
        hashes++;

    }

    return 1000;

}
4

2 に答える 2

5

#define _X_OPEN_SOURCE" " を " " に変更してみてください#define _XOPEN_SOURCE

于 2013-07-07T06:03:48.220 に答える
2

通常、 には番号を指定する必要があります_XOPEN_SOURCE。有効な値は次のとおりです。

/*
** Include this file before including system headers.  By default, with
** C99 support from the compiler, it requests POSIX 2001 support.  With
** C89 support only, it requests POSIX 1997 support.  Override the
** default behaviour by setting either _XOPEN_SOURCE or _POSIX_C_SOURCE.
*/

/* _XOPEN_SOURCE 700 is loosely equivalent to _POSIX_C_SOURCE 200809L */
/* _XOPEN_SOURCE 600 is loosely equivalent to _POSIX_C_SOURCE 200112L */
/* _XOPEN_SOURCE 500 is loosely equivalent to _POSIX_C_SOURCE 199506L */

#if !defined(_XOPEN_SOURCE) && !defined(_POSIX_C_SOURCE)
#if __STDC_VERSION__ >= 199901L
#define _XOPEN_SOURCE 600   /* SUS v3, POSIX 1003.1 2004 (POSIX 2001 + Corrigenda) */
#else
#define _XOPEN_SOURCE 500   /* SUS v2, POSIX 1003.1 1997 */
#endif /* __STDC_VERSION__ */
#endif /* !_XOPEN_SOURCE && !_POSIX_C_SOURCE */

600 ではなく 700 を使用することをお勧めします。プラットフォームによって異なります。ただし、正しいスペルを使用すると、簡単に書くことができ#define _XOPEN_SOURCE、それによって も定義crypt()されます。


また、終了ステータスは 8 ビット値に制限されていることに注意してください。したがって、から 1000 を返すことは、main()を返すことと同じ1000 % 256です。また、コードの 34 行目を修正する必要があります。

        printf("Hash %d: %s\n", hashes, hash);

次のようにする必要があります。

        printf("Hash %lld: %s\n", hashes, hash);
于 2013-07-07T06:07:41.337 に答える