小编Car*_*rum的帖子

找到C中角色最右边的出现?

嘿所有,我正在尝试找到字符串中字符或字符数的数字位置.我能够弄清楚如何在字符串"abcd"中查看字符"a"的位置,但如果我输入"abcda"它只打印出0,这意味着它只计算第一个实例.我想找到这个字符串的最后或最右边的出现.这是我到目前为止所拥有的:

#include <stdio.h>


main(){

char s[20];
char t[20];
int pp;
printf("Enter a FULL string: \n");
scanf("%s", s);

printf("Enter what you want to find: \n");
scanf("%s", t);

pp = strindex(s, t);

printf("%d", pp);

}



/* string index */

int strindex(char s[], char t[]){

int i, j, k, c;

for (i = 0; s[i] != '\0'; i++){

for (j=i, k = 0; t[k] != '\0' && s[j] == t[k]; j++, k++);
if (k > 0 && t[k] == '\0')

return i;




} …
Run Code Online (Sandbox Code Playgroud)

c string

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

关于shell脚本-env变量

有一个shell脚本来读取特定目录中的文件.

#!/bin/bash
for fspec in /exp/dira/test/ready/* ; do
done
Run Code Online (Sandbox Code Playgroud)

我想修改unix shell脚本,以便从环境变量中检索路径.

export CUST_DATA=${_FX_DATA_}/test 已经通过.profile在环境中设置了这个变量

#!/bin/bash
READY_FILES= "$CUST_DATA/ready"
for fspec in $READY_FILES/* ; do
done
Run Code Online (Sandbox Code Playgroud)

我尝试了以上但它不起作用.

unix shell

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

可可非原子性质

当您查看一些Objective-C代码时,您经常会看到定义为非原子的类属性.为什么?当你不使用线程时,它是否会给你一些性能提升,还是有其他原因?

cocoa properties objective-c atomicity

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

目标c引用和变量

我正在尝试做这样的事情:

NSAppleScript *sendCharlieImput = [[NSAppleScript alloc] initWithSource:@"tell application \"terminal\" to do script " charlieImputSelf " in front window"];
[sendCharlieImput executeAndReturnError:nil];
Run Code Online (Sandbox Code Playgroud)

变量charlieImputSelf将作为命令放入终端窗口.但我需要将charlieImputSelf放在2个qoutes之间(如上所述).这显然不是正确的方法.有人可以帮忙吗?

谢谢!以利亚

variables quotes xcode objective-c

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

我可以在iphone目标c的警报中使用NSStrings吗?

我正在尝试创建一个用户单击按钮的应用程序,并弹出一个警告,其中包含文本字段中的文本.但每当我尝试,我只是得到一个空白的警报.这是我的代码:

@synthesize label;

@synthesize textBox1;

@synthesize text;

- (IBAction)buttonClick {
 UIAlertView *someText = [[UIAlertView alloc] initWithTitle: @"Text from textbox1" message: text delegate: self cancelButtonTitle: @"OK" otherButtonTitles: nil];
 [someText show];
 [someText release];
 text = textBox1.text;
 label.text = text;
}
Run Code Online (Sandbox Code Playgroud)

我做错了什么似乎一切都到位应有的样子.我认为答案可能与NSLog()有关.

iphone objective-c alerts nsstring

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

关于在C中等同数组的问题

假设我有两个int数组x和y,它们都有长度3. x = {0,1,2}.

是否有任何一步将x的值分配给y.当我做y = x,并尝试打印y的值,

代码无法编译.

我不想经历编写for循环的痛苦,写y [i] = x [i]

c arrays

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

x86汇编代码

谁能告诉我x86 ASM中的以下代码是什么?它只是一个较大文件的一部分,但只是这一点让我失望.

find_max:
  6 .LFB0:
  7         .cfi_startproc
  8         pushq   %rbp
  9         .cfi_def_cfa_offset 16
 10         movq    %rsp, %rbp
 11         .cfi_offset 6, -16
 12         .cfi_def_cfa_register 6
 13         movl    %edi, -20(%rbp)
 14         movl    -20(%rbp), %eax
 15         cltq
 16         movl    a(,%rax,4), %eax
 17         movl    %eax, -4(%rbp)
 18         movl    -20(%rbp), %eax
 19         movl    %eax, -8(%rbp)
Run Code Online (Sandbox Code Playgroud)

特别,

  • 第13行的%edi最初是什么?
  • 为什么代码引用-20(%rbp)?
  • 第16行究竟做了什么?
  • 切换32位寄存器和64位寄存器背后的智慧是什么(例如在第15行的情况下)?

我为了得到这个而拆解的C代码如下所示:

extern int a[];

int find_max(int n)
{
    int max = a[n];
    int pos = n;
    int x;

    while (n > 0)
    {
        n--;
        x …
Run Code Online (Sandbox Code Playgroud)

x86 assembly disassembly

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

SCNuFAST16 PRIuFAST16警告:格式为未知转换类型字符0x20

test.c: In function ‘main’:
test.c:10: warning: unknown conversion type character 0x20 in format
test.c:10: warning: unknown conversion type character 0x20 in format
test.c:12: warning: conversion lackstype at end of format
test.c:12: warning: unknown conversion type character 0xa in format
test.c:12: warning: conversion lacks type at end of format
test.c:12: warning: unknown conversion type character 0xa in format
Run Code Online (Sandbox Code Playgroud)

gcc test.c -o test

#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

int main(int argc,char *argv[]){

    uint_fast16_t n_curve,n_pt;

    printf("Please enter new value \n");
    scanf( "% …
Run Code Online (Sandbox Code Playgroud)

c

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

未定义的参考/未解析的外部符号

我正在尝试使用WinSock.h头文件,但我得到以下任何一个错误:在VS2010(C++)中:

Unresolved External Symbol to [the function included in winsock.g, e.g socket()]
Run Code Online (Sandbox Code Playgroud)

在gcc命令行(C)中:

Undefined Reference to [the function included in winsock.g, e.g socket()]
Run Code Online (Sandbox Code Playgroud)

代码很简单:只包含Winsock.h头文件然后

SOCKET s =  socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
Run Code Online (Sandbox Code Playgroud)

socket()closesocket()函数有错误......!我在Stackoverflow中搜索并发现了几个主题,但他们都建议更改头文件.我无法在这里更改WinSock.h,因此我需要在使用头文件的实际代码中使用解决方案.有任何想法吗?

c winsock unresolved-external undefined-reference

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

明显的封装

新命令在堆中分配内存以存储对象.静态分配可能导致将对象放在堆栈上.但它们都不是记忆保护区.我可以访问它,它只是对象的地址,然后使用间接运算符,因此指向对象字段:

string str=string("hello");
void** str_this=(void**)&str;
char* str_data= (char*)*str_this;
str_data[0]='s';
str_data[1]=0;
cout <<str_data; // prints "sello"
Run Code Online (Sandbox Code Playgroud)

那么这仍然被认为是封装?是类用户(谁实例化对象)的费用,以避免poiting它的数据?

c++

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