gpt4 book ai didi

c - 文件段错误(核心转储)(C-linux)

转载 作者:行者123 更新时间:2023-11-30 18:28:03 26 4
gpt4 key购买 nike

当我尝试运行此程序时,出现段错误(核心转储)。它编译完美,但我收到错误,我不知道为什么。文件写入肯定有问题,因为没有这个问题就可以正常工作。任何帮助都会很棒。谢谢!

#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <crypt.h>
#include <string.h>

int
main(void)
{

FILE *f=fopen("shadow1.txt","w");


if (f=NULL)
{
printf("ERROR");

}


unsigned long seed[2];
char salt[] = "$1$........";
const char *const seedchars =
"./0123456789ABCDEFGHIJKLMNOPQRST"
"UVWXYZabcdefghijklmnopqrstuvwxyz";
char *password;
int i;

/* Generate a (not very) random seed.
You should do it better than this... */
seed[0] = time(NULL);
seed[1] = getpid() ^ (seed[0] >> 14 & 0x30000);

/* Turn it into printable characters from ‘seedchars’. */
for (i = 0; i < 8; i++)
salt[3+i] = seedchars[(seed[i/5] >> (i%5)*6) & 0x3f];

/* Read in the user’s password and encrypt it. */
password = crypt(getpass("Password:"), salt);

/* Print the results. */
//fprintf(f,"%s $ %s",password);
printf("Success Registration to file !");
fclose(f);
return 0;

}

最佳答案

 if (f=NULL)
{
printf("ERROR");

}

问题是...

关于c - 文件段错误(核心转储)(C-linux),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50165297/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com