嘿所有,我正在尝试找到字符串中字符或字符数的数字位置.我能够弄清楚如何在字符串"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) 有一个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)
我尝试了以上但它不起作用.
当您查看一些Objective-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之间(如上所述).这显然不是正确的方法.有人可以帮忙吗?
谢谢!以利亚
我正在尝试创建一个用户单击按钮的应用程序,并弹出一个警告,其中包含文本字段中的文本.但每当我尝试,我只是得到一个空白的警报.这是我的代码:
@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()有关.
假设我有两个int数组x和y,它们都有长度3. x = {0,1,2}.
是否有任何一步将x的值分配给y.当我做y = x,并尝试打印y的值,
代码无法编译.
我不想经历编写for循环的痛苦,写y [i] = x [i]
谁能告诉我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)
特别,
我为了得到这个而拆解的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) 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) 我正在尝试使用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,因此我需要在使用头文件的实际代码中使用解决方案.有任何想法吗?
新命令在堆中分配内存以存储对象.静态分配可能导致将对象放在堆栈上.但它们都不是记忆保护区.我可以访问它,它只是对象的地址,然后使用间接运算符,因此指向对象字段:
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它的数据?