小编Bod*_*odo的帖子

在记事本中打开由 C 程序创建的文本文件的错误显示

#include<stdio.h>
#include<stdlib.h>
void init(char*filename)
{
    FILE* f = fopen(filename,"w");
    fprintf(f,"%d ",8);
    fprintf(f,"%d ",6);
    int i, j;
    for(i = 0; i < 8; i ++)
    {
        for(j = 0; j < 8; j ++)
        {
            fprintf(f,"%d ", rand()%6);
        }
    }    
    fclose(f);
}
int main()
{
    init("input.txt");
}
Run Code Online (Sandbox Code Playgroud)

当我打开文件时,我看到:

*????????‰‰???????????‰?‰?????????‰?‰?????‰???????????????????????‰*
Run Code Online (Sandbox Code Playgroud)

为什么我看不到rand()%6打印到此文件的值?

我使用 Dev-C++ 5.6.3 运行程序并以 .cpp 格式保存,用记事本打开

c notepad file character-encoding

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

find 命令中的 Unix 大括号扩展

这工作正常:

$ echo email_{ldn,nyk,asp}.log
Run Code Online (Sandbox Code Playgroud)

同样,我想找到略有不同的文件名:

$ find ~ -type f -name email_{ldn,nyk,asp}.log
Run Code Online (Sandbox Code Playgroud)

但上面的命令会导致错误:

find: paths must precede expression: email_nyk.log
Run Code Online (Sandbox Code Playgroud)

任何有关 find 命令中大括号扩展的帮助将非常感激。

linux shell find brace-expansion

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

Grep 数字大于 45 的字符串

我在一个目录中有多个文件。我想提取包含整数值大于 45 的所有文件中的每一行。

目前,我正在使用:

grep "IO resumed after" *
Run Code Online (Sandbox Code Playgroud)

它向我显示此字符串“IO 恢复之后”的所有文件我想再添加一个参数,该参数将 grep 所有行“IO 在 [数字 > 45] 秒后恢复”

unix shell grep agrep

0
推荐指数
1
解决办法
764
查看次数

分解为质因数

所以我遇到了一个我似乎无法解决的问题。我想显示因子和它被提升到的功率(基本上是质因子分解),我已经在 python 中完成了这个,但由于某种原因我不能在 C 中实现它,这就是我想出的

#include<stdio.h>
#include<math.h>

int main()
{
    int i = 2, p, c, n;
    scanf("%d", n);
    while (n > 9)
    {
        p = 0;
        c = 1;
        while (n % i == 0)
        {
            for (int d = 2; d <= i / 2 + 1; d++)
                if (i % d == 0 && i % 2 != 0)
                    c = 0;
            if (c == 1)
            {
                p = p + 1;
                n = n / i; …
Run Code Online (Sandbox Code Playgroud)

c algorithm prime-factoring

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