好吧,所以我知道使用$打印一行的特定参数非常简单:
$ cat file
hello world
$ awk '{print $1}' file
hello
Run Code Online (Sandbox Code Playgroud)
但是如果我想打印2到8的字符怎么办?还是3到7?用awk可以吗?
我不完全确定如何在C中执行此操作:
char* curToken = strtok(string, ";");
//curToken = "ls -l" we will say
//I need a array of strings containing "ls", "-l", and NULL for execvp()
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?
如标题中所述,如果路径是相对路径或绝对路径,我需要确定何时运行程序:
./program #relative
dir/dir2/program #relative
~User/dir/dir2/program #absolute
/home/User/dir/dir2/program #absolute
Run Code Online (Sandbox Code Playgroud)
这是我的测试用例.我怎样才能在shell程序中这样做呢?
或者更一般地说,如何检查路径,$0在这种情况下,是相对的还是绝对的?
在阅读了一些答案之后,我的修改后的代码是:
int pid = fork();
if (pid == -1) {
perror("fork");
} else if (pid == 0) {
if (in) { //if '<' char was found in string inputted by user
int fd0 = open(input, O_RDONLY, 0);
dup2(fd0, STDIN_FILENO);
close(fd0);
in = 0;
}
if (out) { //if '>' was found in string inputted by user
int fd1 = creat(output, 0644);
dup2(fd1, STDOUT_FILENO);
close(fd1);
out = 0;
}
execvp(res[0], res);
perror("execvp");
_exit(1);
} else {
waitpid(pid, 0, 0);
free(res); …Run Code Online (Sandbox Code Playgroud) 我正在绘制一个绘图应用程序,我注意到在32位iPad和64位iPad上加载的纹理存在显着差异.
这是在32位iPad上绘制的纹理:

这是在64位iPad上绘制的纹理:

64位是我想要的,但似乎它可能正在丢失一些数据?
我使用以下代码创建默认画笔纹理:
UIGraphicsBeginImageContext(CGSizeMake(64, 64));
CGContextRef defBrushTextureContext = UIGraphicsGetCurrentContext();
UIGraphicsPushContext(defBrushTextureContext);
size_t num_locations = 3;
CGFloat locations[3] = { 0.0, 0.8, 1.0 };
CGFloat components[12] = { 1.0,1.0,1.0, 1.0,
1.0,1.0,1.0, 1.0,
1.0,1.0,1.0, 0.0 };
CGColorSpaceRef myColorspace = CGColorSpaceCreateDeviceRGB();
CGGradientRef myGradient = CGGradientCreateWithColorComponents (myColorspace, components, locations, num_locations);
CGPoint myCentrePoint = CGPointMake(32, 32);
float myRadius = 20;
CGGradientDrawingOptions options = kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation;
CGContextDrawRadialGradient (UIGraphicsGetCurrentContext(), myGradient, myCentrePoint,
0, myCentrePoint, myRadius,
options);
CFRelease(myGradient);
CFRelease(myColorspace);
UIGraphicsPopContext();
[self setBrushTexture:UIGraphicsGetImageFromCurrentImageContext()];
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)
然后实际设置画笔纹理如下:
-(void) setBrushTexture:(UIImage*)brushImage{
// …Run Code Online (Sandbox Code Playgroud) 我对如何从二进制值转换为c中的char感到困惑.
例如,假设我有01010110,并希望从中打印相应的字母'V'.我该怎么做呢?
谢谢你的帮助!
unsigned long long n = 0;
for (int i = 0; i <= 64; i+=2)
n |= 1ULL << i; //WHAT DOES THIS DO? AH!
Run Code Online (Sandbox Code Playgroud)
我试图围绕这段代码实际上做的第三行.有人请帮忙清除这个!
const char *sentence = "He was not in the cab at the time.";
printf("\"%s\" has %d spaces\n", sentence, (int) ^ {
int i = 0;
int countSpaces = 0;
while (sentence[i] != '\0') {
if (sentence[i] == 0x20) {
countSpaces++;
}
i++;
}
return countSpaces;
});
Run Code Online (Sandbox Code Playgroud)
这段代码只计算一个字符串中的空格,但由于某种原因,它表示1606416608个空格而不是8个.我不确定出了什么问题,所以感谢您的帮助!
我正在使用Linux机器上的C程序,该程序显示作为程序参数的文件的文件类型.程序需要确定文件是否是以下任何一个:目录,设备,(常规)文件,链接,套接字或fifo.我不确定如何确定文件类型.
到目前为止,这是我的代码(不多):
int
main(int argc, char **argv)
{
if( argc == 1 ) /* default: current directory */
puts("Directory");
else
while( --argc > 0 )
determine_ftype(*++argv);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
我有:
#include <stdio.h>
struct DVD {
char *movie_title;
int minutes;
float price;
};
void display_struct(struct DVD *ptr);
int
main()
{
struct DVD movies[10];
movies[0].movie_title = "I Am Legend"; //Don't want to do this
}
void
display_struct(struct DVD *ptr)
{
printf("%s\n%i\n%f\n", ptr->movie_title, ptr->minutes, ptr->price);
}
Run Code Online (Sandbox Code Playgroud)
我想在一个语句中为我的结构数组分配10个电影标题.这可能吗?谢谢!
我不确定出了什么问题.我实现了developers.Facebook.com指定的所有内容,以在我的iOS应用程序中验证Facebook登录.以下是我认为与此问题相关的内容:
我正在制作的应用程序是带有导航控制器的选项卡式应用程序.
我收到以下代码的警告(由Facebook开发者页面提供):
- (IBAction)authButtonAction:(id)sender {
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
// The user has initiated a login, so call the openSession method
// and show the login UX if necessary.
[appDelegate openSessionWithAllowLoginUI:YES];
}
Run Code Online (Sandbox Code Playgroud)
警告是: 使用不兼容类型'id <UIApplicationDelegate>'的表达式初始化'AppDelegate*'
当我点击authButton时,我的iPhone上的Facebook应用程序将打开,并向用户显示有关授予我的应用程序访问发布状态更新的相应消息.但是...控制流程从未返回给我的应用程序,Facebook应用程序保持打开状态.我相信这与上述警告有关.