小编Lir*_*una的帖子

递归CreateDirectory

我以递归方式找到了很多CreatingDirectory的例子,但没有找到我想要的那个例子.

这是规格

给定输入

  1. \\服务器\共享\ AA\BB \立方厘米
  2. C:\ AA\BB \立方厘米

使用帮助程序API

 CreateDirectory (char * path)
 returns true, if successful
 else
 FALSE
Run Code Online (Sandbox Code Playgroud)

条件:不应该有任何解析来区分路径是本地还是服务器共享.

用C或C++编写例程

c recursion share

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

计算部分总和的 MySQL 查询

我应该在 MySQL 数据库中执行什么查询以获得包含源表部分总和的结果?

例如,当我有桌子时:

Id|Val
1 | 1
2 | 2
3 | 3
4 | 4
Run Code Online (Sandbox Code Playgroud)

我想得到这样的结果:

Id|Val
1 | 1
2 | 3 # 1+2
3 | 6 # 1+2+3
4 | 10 # 1+2+3+4
Run Code Online (Sandbox Code Playgroud)

现在我通过一个包含游标和 while 循环的存储过程得到这个结果。我想找到一种更好的方法来做到这一点。

mysql stored-procedures

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

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

使用鼠标缩放2D多边形

我开发了一个基于Python的绘图程序,Whyteboard(https://launchpad.net/whyteboard)

我正在开发功能,允许用户旋转和缩放他们绘制的多边形.这是我的问题:

我有一个Polygon类,其中包含所有点的列表,最后是"关闭".用户可以在我的程序中选择绘制的形状,"高亮"它们,在每个点绘制选择手柄.可以"抓住"这些点以改变其位置,并改变多边形的形状.

我有一个问题:我需要弄清楚如何计算应用于多边形的调整大小"比例".例如,(在按住鼠标的情况下),用户将鼠标从形状移开应该是"增长"动作,并且将鼠标移向形状应该缩小它.

我有代码来执行比例(我认为这是正确的),但我不能创建一个"好"的比例因子.根据答案,下面的代码是我提出的

/ edit - 这是解码的代码.

def rescale(self, x, y):
    """ 
    x and y are the current mouse positions. the center and "original" mouse 
    coords are calculated below
    """
    if not self.center:
        a = sum([x for x, y in self.points]) / len(self.points)
        b = sum([y for x, y in self.points]) / len(self.points)
        self.center = (a, b)
    if not self.orig_click:  # where the user first clicked on
        self.orig_click = (x, y)
    if not self.original_points:  # the …
Run Code Online (Sandbox Code Playgroud)

math polygon draw rescale

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

Unix编程... fork()&execv()帮助... C编程

我正在编写自己的unix终端,我遇到了执行命令的问题:

首先,我将用户输入并将其存储到缓冲区中,然后将单词分开并将它们存储到我的argv []数组中.即命令是"firefox"来启动存储在argv [0]中的firefox

如何启动命令?这就是我想要做的,但我遇到了错误:

void launchProcess(char *command[], char *file){
        pid_t pid;
        pid = fork();
        if (pid == -1) {
                perror("Error when forking");
                exit(EXIT_FAILURE);
        }
        if (pid == 0){                  
                fprintf(stderr, "Child pid = %d\n", getpid());
                execv(file, command);
            }
Run Code Online (Sandbox Code Playgroud)

我打电话的时候:

launchProcess(commandArgv, "STANDARD");
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:错误:launchProcess的冲突类型

c unix exec

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

Linux:GNU排序不排序seq

标题总结了它.

$ echo `seq 0 10` `seq 5 15` | sort -n
0 1 2 3 4 5 6 7 8 9 10 5 6 7 8 9 10 11 12 13 14 15
Run Code Online (Sandbox Code Playgroud)

为什么这不起作用?

即使我不使用seq:

echo '0 1 2 3 4 5 6 7 8 9 10 5 6 7 8 9 10 11 12 13 14 15' | sort -n
0 1 2 3 4 5 6 7 8 9 10 5 6 7 8 9 …
Run Code Online (Sandbox Code Playgroud)

sorting bash gnu-sort

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

删除前三次出现的空格

我需要删除文本文件中每行前三次出现的空格.

我尝试过以下方法:

sed 's/ //3'
Run Code Online (Sandbox Code Playgroud)

这仅删除第三次出现.

sed 's/ //3g'
Run Code Online (Sandbox Code Playgroud)

这样就留下了前三次出现的空间并删除了以下所有内容,这与我想要的完全相反.

regex sed

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

GLSL与openGL2设置问题

我正在尝试将GLSL与openGL 2.0一起使用.

任何人都可以给我一个很好的教程,以便我可以正确设置GLSL.

关心Zeeshan

opengl

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

在简单程序中使用ferror()时出现分段错误.为什么?

为什么下面的代码给出了分段错误?

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

int main()
{
    FILE *file;
    file = fopen("text","r");
    if (file == NULL) printf("Error READING FILE");
    if (ferror(file)) printf("error reading file");    //line 9
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

在gdb中执行backtrace给出: -

> #0  0x00007ffff7ad9d30 in ferror () from /lib/libc.so.6
> #1  0x00000000004005fa in main () at test.c:9

c gdb

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

如何从IP地址获取最后一位数字?

有谁知道如何从PHP中的IP地址获取最后一位数字?

例:

$ip = '200.0.0.12';
Run Code Online (Sandbox Code Playgroud)

如何从IP地址而不是200.0.0.12只获得12?

php

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

RegEx - 只有一封有效的电子邮件

我知道这是我的错,并不复杂,但我自己找不到答案,所以我求求你帮我建立这个RegEx.

我试图避免用户逐行输入多个电子邮件地址,所以我想将"@"事件限制为仅1并检查是否有逗号(,)....

这是RegEx的简化版本,我已经用它来检查输入....

\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b
Run Code Online (Sandbox Code Playgroud)

我怎么能介绍一个部分来检查最后一部分没有(@,)?

提前致谢

regex email

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

标签 统计

c ×3

regex ×2

bash ×1

draw ×1

email ×1

exec ×1

gdb ×1

gnu-sort ×1

math ×1

mysql ×1

opengl ×1

php ×1

polygon ×1

recursion ×1

rescale ×1

ruby ×1

sed ×1

share ×1

sorting ×1

stored-procedures ×1

unix ×1