小编urw*_*CFC的帖子

使用C-if条件实现cd系统调用

这是使用C实现cd系统调用的代码.此代码的问题是它没有进入if条件 if(strcmp(buffer,"cd") == 0) 而我无法理解为什么.

#include<sys/stat.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include<dirent.h>
#include<error.h>

#define BUFFERSIZE 20
int main(){

char *args[80]; 
char buffer[BUFFERSIZE];
char *prompt = "OS";
char *a = ">";
printf("%s%s",prompt,a); 
fgets(buffer, BUFFERSIZE, stdin);  

char *tok; 
tok = strtok (buffer," ");


while(buffer != NULL){ 
   buffer[strlen(buffer)-1] = '\0';  
   pid_t pid;
   pid = fork();
   if(pid < 0){
      fprintf(stderr, "Fork failed");
      return 1;
   }
   else if(pid == 0){

       if(strcmp(buffer,"cd") == 0){
         tok = strtok(NULL,"\n");
         cd(tok);
       }
       printf("%s%s",prompt,a); 
       fgets(buffer, BUFFERSIZE, stdin); …
Run Code Online (Sandbox Code Playgroud)

c cd

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

R- knitr:kable - 如何显示没有列名的表格?

目前,我有这个数据框(PS):

带列标题的表

我显示此表的代码是:

kable(PS) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"))
Run Code Online (Sandbox Code Playgroud)

我想显示没有列名的表,如下所示: 在此输入图像描述

问题是

1)列名称应为非空,并且尝试使用空名称将具有不受支持的结果

2)如果我转换数据框并删除列名,然后像这样使用kable:

PS.mat <- as.matrix(PS)
colnames(PS.mat) <- NULL
kable(PS) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"))
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

Error in kable_info$colnames[[length(kable_info$colnames)]] : attempt to select less than one element in integerOneIndex
Run Code Online (Sandbox Code Playgroud)

我也尝试了以下参数,但没有结果

kable(PS, col.names = NA) 
Run Code Online (Sandbox Code Playgroud)

编辑1:

一个可重复的例子:

if (!require(pacman)) install.packages("pacman")
p_load("lubridate","knitr","kableExtra","scales")

Statistics <- c("AUM",
            "Minimum Managed Account Size",
            "Liquidity",
            "Average Margin / Equity",
            "Roundturns / $ Million / Year",
            "Incentive Fees",
            "Instruments Traded")
Value <- c("$30K","$30K","Daily","50%","6,933","25%","ES")
AI <- …
Run Code Online (Sandbox Code Playgroud)

r knitr flexdashboard

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

SQL - 对多列的所有时间、30 天和 90 天的数据进行汇总

背景:

我有看起来像这样的数据

date        src    subsrc   subsubsrc   param1  param2
2020-02-01  src1    ksjd    dfd8        47      31    
2020-02-02  src1    djsk    zmnc        44      95    
2020-02-03  src2    skdj    awes        92      100   
2020-02-04  src2    mxsf    kajs        80      2     
2020-02-05  src3    skdj    asio        46      53    
2020-02-06  src3    dekl    jdqo        19      18    
2020-02-07  src3    dskl    dqqq        69      18    
2020-02-08  src4    sqip    riow        64      46    
2020-02-09  src5    ss01    qwep        34      34    
Run Code Online (Sandbox Code Playgroud)

我正在尝试汇总过去 30 天和过去 90 天的所有时间(无滚动总和)

所以我的最终数据看起来像这样:

src     subsrc  subsubsrc   p1_all  p1_30   p1_90   p2_all  p2_30   p2_90
src1    ksjd    dfd8 …
Run Code Online (Sandbox Code Playgroud)

mysql sql pivot group-by query-optimization

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

在Linux中实现rm命令的C代码中的分段错误

这是一段编译很好但在运行时给出分段错误的代码.任何人都可以告诉我如何解决这个问题.代码在C中实现rm系统调用.

#include<sys/stat.h>
#include<unistd.h>
#include<dirent.h>
#include<error.h>
#include <stdio.h>
#include <string.h>


int rmq(char*pth)
{
  char path[1000]; //hold the file name to be removed
  strcpy(path,pth);
  char *b; // stores the complete path of the file to be removed
  struct dirent *d;
  DIR *dir;

  char cwd[256]; //holds current working directory
  getcwd(cwd, sizeof(cwd));  
  dir = opendir(cwd);
  char path1[1000]; //for recursively moving through dir and subdir
  strcpy(path1,cwd);

  char newp[1000];
  struct stat buf;

  while((d = readdir(dir))) //if there are directories to be read 
  {  
     if(!strcmp(d->d_name,".") || !strcmp(d->d_name,"..")) …
Run Code Online (Sandbox Code Playgroud)

c segmentation-fault

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