小编das*_*ght的帖子

将在命令行中输入的十六进制值存储到整数

#include<stdio.h>
int main(int argc,char* argv[]){
        int hex;
        printf("\n argc : %d argv[1] : %s \n",argc,argv[1]);
        hex = argv[1];
        printf("\n hex : %x \n",hex);
        return 0;
}
Run Code Online (Sandbox Code Playgroud)

O/P:

[root@ld]# ./a.out 343ed4

 argc : 2 argv[1] : 343ed4

 hex : 9e1a4aa8
Run Code Online (Sandbox Code Playgroud)

我想存储从命令行参数获得的十六进制值并将其存储在整数上.上面的程序,当存储十六进制值时,会给出与用户给定值不同的结果.不能使用atoi,因为它会在数字之后剪切字母表.如何将在命令行参数中输入的十六进制存储为整数.

c

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

在Swift中将值从一个视图控制器传递到另一个视图控制器

我正在研究Swift,我在tableview的didSelectRowAtIndexPath方法中遇到了错误.我想将值传递给另一个视图控制器,即'secondViewController'.这里EmployeesId是一个数组.相关代码如下:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    var view: Dashboard = self.storyboard?.instantiateViewControllerWithIdentifier("Dashboard") as Dashboard

    self.navigationController?.pushViewController(view, animated: true)
    secondViewController.UserId = employeesId[indexPath.item]  //getting an error here.
}
Run Code Online (Sandbox Code Playgroud)

但我收到此错误:致命错误:在展开Optional值时意外发现nil.

任何帮助将不胜感激.

ios swift

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

从索引存在于另一个aray中的一个数组中删除元素

包含N个对象的数组A1.另一个包含表示第一个数组中索引的数字的数组A2.您需要从A2中删除A2中的索引所在的元素并生成压缩数组.例如:

A1 = [ a, b, c, d, e, f, g ] // N elements and N is large
A2 = [ 5, 1 ] // k elements and k is small (and constant)
Answer = [ a, c, d, e, g, _, _ ]
Run Code Online (Sandbox Code Playgroud)

我写了C#代码,如:

public class CompactingArray
{
    private Compact(array A1 , array A2)
    {
        var hash = new Hashset<int>(A2);
        foreach(int c in hash)
        {
            A1.remove(c,1);
        }

        Console.WriteLine(A1);
    }
}
Run Code Online (Sandbox Code Playgroud)

我需要O(n)复杂度代码而不使用任何内置函数.请在不使用任何内置函数的情况下建议C#代码.

c# arrays algorithm

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

如何在Java中编写简短的逻辑表达式?

有没有办法对同一个变量进行连续的逻辑运算?

例:

if (animation.getStatus() == Animation.Status.PAUSED || animation.getStatus() == Animation.Status.STOPPED) {
    animation.playFromStart();
} else if (animation.getStatus() == Animation.Status.RUNNING) {
    animation.stop();
}
Run Code Online (Sandbox Code Playgroud)

你在if子句中看到我检查了animation.getStatus()两次,一次是暂停,一次是停止.有没有办法让它变得像animation.getStatus() == Animation.Status.PAUSED || Animation.Status.STOPPED

我确定已经问过这个问题,但我真的不知道要搜索什么,所以如果这是重复的话,我很抱歉.

java logical-operators

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

Java颠倒了在for循环中访问列表的顺序

我想颠倒在for()中访问List的顺序

这是我的实际代码

for(int i = 0; i < states.size(); i++) {
    System.out.println(states.size());
    states.get(i).update(true); // restore the first blockstate
    states.remove(i); // remove the first blockstate from the list
}
Run Code Online (Sandbox Code Playgroud)

这段代码有效,但我想反过来.我已经尝试过其他方式,比如使用,i--但它没有用.有人可以提出建议吗?

java

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

哪种类型的数据结构是栈?

我有一个简单的问题:哪种数据结构是堆栈?它是静态数据结构还是动态数据结构?我一直在寻找答案但找不到它,因此我得到了自己的“解释” - 我想,当您可以通过使用数组或链表来实现它时,它可以......两者兼而有之?,取决于关于实施?我的推理有意义吗?

stack data-structures

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

在Swift中搜索字符串数组的字典

我想在映射到字符串数组的int字典中查找字符串值.我可以使用下面的代码来处理映射到字符串但不是字符串数组的整数字典.我怎样才能做到这一点?我尝试在我的过滤器中嵌套另一个过滤器,但没有运气.

let dict = [1 : ["one", "two"], 2 : ["red", "green"], 3 : ["World", "are", "you"]]

// Doesn't work for array of strings.
let keys = dict.filter {
    return $0.1.containsString("are")  // Should return 3
}.map {
    return $0.0
}
Run Code Online (Sandbox Code Playgroud)

dictionary functional-programming swift

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

是否可以使对象构造异步?

我有一个async从我的webservice检索信息的功能

private static async Task<DataClass> retrievData(){
...
}
Run Code Online (Sandbox Code Playgroud)

我需要在我的构造函数上提供此信息,但我无法阻止我的应用程序的其余部分

所以我想做点什么

public class MyClass {
     private DataClass theData;
     public async Myclass(){
          var dataTemp = await Server.retrievData();
          if(dataTemp.ValidatorNumber == Server.Validator.FULL)
              theData = dataTemp
          ...
     }
Run Code Online (Sandbox Code Playgroud)

但这是不允许的.有解决办法吗?

c# async-await

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

在Swift中迭代多个数组

我希望使用枚举方法在Swift中基本匹配两个不同的数组.所以,如果我有:

let array1 = ["a", "b", "c", "d"]
let array2 = ["1", "2", "3", "4"]
Run Code Online (Sandbox Code Playgroud)

我需要返回一个新的数组:

newArray = ["1. a1", "2. b2", "3. c3", "4. d4"]
Run Code Online (Sandbox Code Playgroud)

我如何制作这样的数组?

arrays enumerate ios swift

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

C中的"动态继承"

我编写了以下代码并且它可以工作,但我想知道是否可以确保它在所有x86机器上始终有效.

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

typedef struct Base {
  int a;
  float b;
} Base;

typedef struct Derived1 {
  int a;      // This two members have the same position as in the Base
  float b;

  // adding some other members to this struct
  int otherMember;
  int otherMember2;
} Derived1;

int main()
{
  Base *bases[2];

  // Filling the array with different structs
  bases[0] = (Base*) malloc(sizeof(Base));
  bases[1] = (Base*) malloc(sizeof(Derived1));

  bases[1]->a = 5;
  Derived1 *d1 = (Derived1*) bases[1];

  if(d1->a == 5) …
Run Code Online (Sandbox Code Playgroud)

c oop struct pointers

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