小编Gab*_*abe的帖子

如何获取文本文件并使用带编号的行创建副本

这首诗保存在一个文本文件中:

'Twas brillig, and the slithy toves
   Did gyre and gimble in the wabe;
All mimsy were the borogroves,
   And the mom raths outgrabe.
               - Lewis Carroll

我想创建该文件的副本并更改名称,并使输出看起来像这样:

1: 'Twas brillig, and the slithy toves
2:   Did gyre and gimble in the wabe;
3: All mimsy were the borogroves,
4:   And the mom raths outgrabe.
5:             - Lewis Carroll

这可以使用循环来完成还是有更简单的方法来做到这一点?

python

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

交叉线程操作错误

      if (listBox1.InvokeRequired)
       {
           listBox = new StringBuilder(this.listBox1.Text);
       }
Run Code Online (Sandbox Code Playgroud)

这是c#中的代码,执行时会为listBox1生成无效的交叉线程操作错误,listBox1是我表单中的列表框.请你们告诉我为什么?我也使用invokeRequired方法,也没有更改列表框的内容.

c# multithreading

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

为什么这个简单的程序会输出这么多字符?

这是我的短装配程序:

; This code has been generated by the 7Basic
; compiler <http://launchpad.net/7basic>

extern printf

; Initialized data

      SECTION .data
f_0 dd 5.5
printf_f: db "%f",10,0

      SECTION .text

; Code

global main
  main:
push ebp
mov ebp,esp

push dword [f_0]
push printf_f
call printf
add esp,8

mov esp,ebp
pop ebp
mov eax,0
ret
Run Code Online (Sandbox Code Playgroud)

该程序应该做的是打印5.5,但它打印:

-4101885043414705786563701568963176764603483495211119243453355953219830430011006780068899468997203661787555969981250050126586203424320244681571103387315766489883301796219461838644670607029711305942610787622864198879363376953745160639821663444829839767678538571371627347101810056161000273217639447052410683392.000000

我究竟做错了什么?代码将两个参数推送到printf()然后调用它.没什么复杂的.


更新:我认为我修复了这个问题还为时过早.我已经更新了代码.

x86 assembly printf x87

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

从二进制文件中读取变量大小的字符串(VB6与C#)

我有一个包含以下内容的二进制文件:

替代文字

以下代码用于在旧的VB6程序中读取此内容:

Private Type tpClient
    Firstname As String
    LastName As String
    Birth As String
    Adres As String
    Geslacht As String
    IDNummer As Long
    SSNummer As String
    DatabaseID As Long
    Telefoon1 As String
    Telefoon2 As String
End Type

Open strFilePath For Random Access Read As #intFileNumber
Get #intFileNumber, 1, ClientData ' ClientData is of type tpClient
Run Code Online (Sandbox Code Playgroud)

现在我想用我的新C#程序来阅读这个:

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct PatientStruct
{
    [MarshalAs(UnmanagedType.BStr)]
    public string FirstName;

    [MarshalAs(UnmanagedType.BStr)]
    public string LastName;

    [MarshalAs(UnmanagedType.BStr)]
    public string BirthDate;

    [MarshalAs(UnmanagedType.BStr)]
    public string Address; …
Run Code Online (Sandbox Code Playgroud)

.net c# vb6 binary

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

C#LPT名称问题

如何在C#中将输出发送到LPT.我使用SerialPort类.我将端口名称设置为"LPT1",我收到此错误.

给定的端口名称不以COM/com开头,也不会解析为有效的串行端口.参数名称:portName

该怎么办?

.net c# port serial-port lpt

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

Seg Fault(Whats Wrong,strcpy)

在GDB中我得到:

 
(gdb) backtrace
0  0xb7d91544 in strcpy () from /lib/libc.so.6
1  0x08048982 in ISBN::ISBN(char const*, ISBNPrefix&) ()
2  0x08048d4a in main ()
(gdb)

从这段代码:

ISBN::ISBN(const char* str, ISBNPrefix& list) {
    if(isValid(str)) {
            isSet = true;
            sprintf(*isbnStr,"%s",str);
    }
}
Run Code Online (Sandbox Code Playgroud)

究竟是什么导致了这个?

isbnStr是在标题中创建的:

class ISBN
{
 ...
    char* isbnStr[11];
 ...
Run Code Online (Sandbox Code Playgroud)

关于我在这里做什么导致这个段错误的任何想法?

主要是:

ISBN* isbn = new ISBN("7999999008",*prefix);
Run Code Online (Sandbox Code Playgroud)

c++

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

如何为这个问题实现这个O(1)算法?

我有变量x,函数f1(x),f2(x),... fn(x)(n最多可达1百万).这些函数的值是1还是0.那么,如何编写算法,可以快速获取返回1的函数?谢谢.

我在这里介绍我的.它具有O(n)时间复杂度,这是不够有效的.

List funHaveTrueValues = new ArrayList();

for (int i=1; i<=n; ++i){
 if (fi(x)==true){
   funHaveTrueValues.add(fi);
  }
 }
}
Run Code Online (Sandbox Code Playgroud)

任何人都可以提出O(1)算法吗?谢谢!

algorithm performance big-o

0
推荐指数
2
解决办法
324
查看次数

字符串不是[Char]吗?

据我所知String,type在Haskell:

type String = [Char]
Run Code Online (Sandbox Code Playgroud)

然后我不明白为什么以下代码:

stringDecode :: String -> Maybe String
stringDecode s =
  let
    splitByColon x' = splitAt x' s
  in case findIndex (\b -> b == ':') s of
     (Just x)  -> snd (splitByColon x) 
     (Nothing) -> Nothing
Run Code Online (Sandbox Code Playgroud)

编译时出现以下类型错误:

Couldn't match expected type `Maybe String'
            with actual type `[Char]'
Expected type: ([Char], Maybe String)
  Actual type: ([Char], [Char])
In the return type of a call of `splitByColon'
In the first argument of `snd', …
Run Code Online (Sandbox Code Playgroud)

haskell

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

char赋值数组不起作用

我试图在switch语句中改变我的char数组[10]的值,这样,如果我们有case 1,我的char数组[10] ="january",或者如果我们有case 2,那么array [10] ="二月"等等.问题是我得到错误信息,我知道我做错了什么.任何帮助将非常感激.这是我用Dev-C++编写的switch语句.

char month[10];
switch (i)
{
 case 1:
       month[10]="January";
      cout<<month<<endl;
      break; 
 case 2:
       month[10]="February";
      cout<<month<<endl;
      break;
} 
Run Code Online (Sandbox Code Playgroud)

c++ arrays char switch-statement

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

Python逻辑操作

我是python的新手,我正在使用Scrapy库进行网络抓取项目.我没有使用内置域限制,因为我想检查域外页面的任何链接是否已经死亡.但是,我仍然希望区域内的页面与其他页面不同,并且在解析响应之前尝试手动确定站点是否在域内.

回复网址:

http://www.siteSection1.domainName.com
Run Code Online (Sandbox Code Playgroud)

如果声明:

if 'domainName.com' and ('siteSection1' or 'siteSection2' or 'siteSection3') in response.url:
    parsePageInDomain()
Run Code Online (Sandbox Code Playgroud)

上述声明是真实的(页面解析),如果"siteSection1"是第一次出现在或公司的名单,但如果响应URL是相同的,但如果语句是下面也不会解析页面:

if 'domainName.com' and ('siteSection2' or 'siteSection1' or 'siteSection3') in response.url:
        parsePageInDomain()
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?我无法非常清楚地思考逻辑运算符的情况,我们将非常感谢任何指导.谢谢!

python logic operators scrapy

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