- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
目前,这是我创建的代码,但我似乎找不到其背后的问题。我正在编写一个加密程序
int countWords(FILE *f){
int count = 0;
char ch;
while ((ch = fgetc(f)) != EOF){
if (ch == '\n')
count++;
}
return count;
}
int main ( int argc, char *argv[] ){
//int min > 0;
//int max >= int min;
time_t current_time;
char* c_time_string;
current_time = time(NULL);
/* Convert to local time format. */
c_time_string = ctime(¤t_time);
printf("Program started %s\n", c_time_string);
if ( argc != 2 ){
printf( "usage: %s filename\n", argv[0] );
}else {
int wordCount = 0;
FILE *file = fopen( argv[1], "r" );
//wordCount += countWords(file);
//printf("Total number words processed => %d\n", wordCount);
if ( file == 0 ){
printf( "Could not open file.\nProgram halted. Please verify the file path and try again.\n" );
}else {
int x;
while ( ( x = fgetc( file ) ) != EOF ){
printf("%c", x );
}
fclose( file );
}
/// CRYPT ///
char * plaintext = argv[1] ;
char * hash_type_1 = "$1$"; // type 1 implies md5 (number of iteration is only 1000 rounds)
char * hash_type_2 = "$6$"; // type 2 implies sha-512 (default value as in yr 2017, number of iteration is minimum 10,000 rounds )
char * salt_1 ="$"; // a simplified 0 length salt.
char * salt_2 ="ABCD1234$"; // a normal 8 character salt.
char * result;
char encyption_scheme[20]; // 20 is more than enough.
// prepare the first call using md5 and empty salt
strcpy(encyption_scheme,hash_type_1);
strcat(encyption_scheme,salt_1);
result = crypt(plaintext,encyption_scheme);
printf("MD5: %s\n",result);
// prepare the second call using sha-512 and a 8-char salt
strcpy(encyption_scheme,hash_type_2);
strcat(encyption_scheme,salt_2);
result = crypt(plaintext,encyption_scheme);
printf("Sha512: %s\n",result);
printf("Program ended %s\n", c_time_string);
//transfer the output to mytab2411.txt//
result = freopen("mytab2411.txt", "w+", stdout);
}
return 0;
}
我的编码需要一些帮助。我正在尝试编写一个程序,该程序能够将程序的输出传输到空文件。请帮我找出我的错误。
最佳答案
关于:
//transfer the output to mytab2411.txt//
result = freopen("mytab2411.txt", "w+", stdout);
对 I/O 的修改仅适用于调用后的输出。
建议将此语句放在代码“加密”部分的开头。
关于c - 如何使用 freopen 重定向输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48002129/
编辑:我已经成功缩小了问题范围,但对我来说仍然没有多大意义。我的代码变成8行: int savedOut = dup(1); printf("Changing the outstream to p
我是 C++ 的初学者,我有一个超出我能力范围的问题。我在 GNU GCC 下编译。我用 #include 也称为: #include 在我的程序中的某个时刻,我告诉程序使用文件 de_facut.t
知道为什么会这样: #include #include int nrpart; int k; void main() { printf("lol"); freopen("p2.in
我正在使用我的共享库将 freopen 用于 GUI 应用程序,这样我就可以将调试消息从 stdout 重定向到一个文件 我一直在使用基于 C++ 引用站点片段的代码: /* freopen exam
我正在编写一个 Qt GUI 应用程序(用于进行 XSL 转换)。要将错误消息打印到文件,我正在使用如下调用: freopen("my-error-file.txt", "w", stderr); /
给定以下函数: freopen("file.txt","w",stdout); 将 stdout 重定向到一个文件中,如何使 stdout 重定向回控制台? 我会注意到,是的,还有其他类似的问题,但是
我在执行 2 个连续的 freopen 时遇到错误,file1 包含偶数个整数 int x, y; freopen("file1", "r", stdin); while (cin >> x) {
我正在尝试使用文件重定向 stdout 和 stderr 的输出。我正在使用 freopen,它会在正确的目录中创建文件,但文件是空白的。当我注释掉重定向 stdout 和 stderr 的代码时 -
试图implement freopen() ,据我所知,我在标准中找到了一条实际上没有指定任何内容的规范。 所以... freopen()将关闭流(忽略错误),清除其错误和 EOF 标志,重置宽方向,
我有一个程序,该程序获取两个路径作为命令行参数。第一个参数(实际上是第二个参数,因为第一个是命令名称本身)是程序从中读取文件(输入文件)的路径。第二个是程序写入的文件(输出文件)的路径。 int ma
目前,这是我创建的代码,但我似乎找不到其背后的问题。我正在编写一个加密程序 int countWords(FILE *f){ int count = 0; char ch; whil
我正在尝试使用 freopen 写入子目录内的文件: freopen("output/output-1.txt", "w", stdout); 我尝试将其更改为输出到当前目录并且它有效。当目标输出文件
我有一堆批处理文件,用程序 A 做这样的事情: A > log.txt ; grep 'result:' log.txt > result.txt || raise_hell.sh 我想做的是修改 A
我正在尝试创建一个文件,其名称是一个字符串常量,但是一个由常量字符串“List”组成的字符串,一个整数++ 一个扩展名。这是我的代码: #include #include #include #i
来自 In multi thread application how can i redirect stderr & stdout in separate file as per thread? 的扩
这是 How to capture output of printf? 的后续行动- 特别是 jxh 的回答。 我在 Viesturs 在 2018 年的答案中遇到了同样的问题。有人建议他打开一个新问
freopen 的签名是FILE * freopen (const char * filename, const char * mode, FILE * stream) 根据文档,返回值与 strea
我尝试编译并运行具有以下几行的 C 代码: FILE *preproc_producer = NULL; preproc_producer = tmpfile(); // preproc_produc
你好,我想知道在我调用之后我们如何再次从 stdin 获取输入: freopen("Smefile.txt","r",stdin); 准确地说,我希望我的程序的第一个部分应该从指定的文件中获取输入,下
我尝试使用以下命令从标准输出重定向我的 C++ 程序中的输出: freopen(cmd.c_str(),"w",stdout); 然后调用system执行cmd。我也尝试过 fork 然后调用
我是一名优秀的程序员,十分优秀!