无法从javascript功能返回值

时间:2016-12-07 04:15:48

标签: javascript function return

我有一个通用函数,用于从外部源检索数据作为GET请求。我能够在console.log()函数内部的响应文本很好,所以我知道它检索了预期的数据,但是我所做的每次尝试都将所述数据返回给变量都失败了。关于如何继续,我现在完全不知所措。任何指针都将非常感激。

另外值得一提的是,由于平台的限制,我希望纯粹用javascript来做这件事。

char* outputName=NULL;

int isNumber(char number[]){
 int i;
 if (number[0]=='-'){
   i=1;
 }
 while(number[i] != '\0'){
   if (!isdigit(number[i])){
   return 0;
  }
   i++;
 }
return 1;
}

void catcher(int signo) {
 printf("The program is exiting early");
 remove(outputName);
 exit(1);
}

int main(int argc, char *argv[]) {
 if (argc != 4){
   fprintf(stderr,"Incorrect number of arguments, must supply three.\n");
   exit(1);
}
 char* inputName = argv[1];
 outputName=argv[2];
 signal(SIGINT, catcher);
 int result=isNumber(argv[3]);
 if (result==0){
   fprintf(stderr, "Invalid maximum line length, please enter an integer\n");
   exit(1);
 }
 int maxChars= (atoi(argv[3]))+1;
 if ((maxChars-1)<1){
   fprintf(stderr, "Invalid third maximum line length, please enter an integer greater than zero\                                          
.\n");
  exit(1);
 }
 FILE* inFile = fopen(inputName, "r");
 if (inFile==NULL){
   fprintf(stderr,"Error while opening %s.\n", inputName);
   exit(1);
 }
 FILE* outFile= fopen(outputName, "w");
 if (outFile==NULL){
   fprintf(stderr,"Error while opening %s.\n", outputName);
   exit(1);
}                                                                                               
 char line[maxChars];
 int done=0;
 while (!done){
   char *readLine=fgets(line,maxChars,inFile);
   if (readLine==NULL){
     if (errno==0){
       done=1;
  }
   else{
     fprintf(stderr, "Error when reading line from input file");
     exit(1);
  }
}
 int len=strlen(line);
 if (line[len-1]!='\n'){
   line[len]='\n';
   line[len+1]='\0';
   char current=' ';
   while (current != '\n'){
     current=getc(inFile);
   }
 }
 if (!done){
  fputs(line, outFile);
  if (errno!=0){
    fprintf(stderr, "Error when writing line to output file");
    exit(1);
    }
  }
 }
return 0;
}

0 个答案:

没有答案