为什么总是重播-1

时间:2018-12-05 01:54:30

标签: c execvp

当我测试程序时,它总是重新运行-1。我首先输入txt文件并正确读取了文本,所以我的问题是我无法使execvp正常工作。我需要在execvp函数中编写哪些文档才能使其正常工作。谁能解释这个程序为什么不起作用。

int morph(char* number);                                       

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


FILE *fileName = NULL;                                                   
char numberFromFile[MAX_STRING] = "";                                    

// TODO: add work also goes in this function. 

// check the number of command line parmeters           
// if incorrect number print message and exits                           
if (argc < 2) {                                                         
    printf("usage %s filename \n",argv[0]);         
    printf("2 \n");                                  
} else {                                             
    // check if file exists                   
    fileName = fopen(argv[1], "r");                        
    if (fileName == NULL) {  
        printf("file %s does not exits \n", argv[0]);         
        printf("3 \n");                
    } else {   
        int number = 0;

        fscanf(fileName, "%s", numberFromFile);
        //printf("%s \n",numberFromFile); 

        //strcpy(numberFromFile, "1233");

        number = morph(numberFromFile);

    printf("%d \n",number);
    //}                                                                        
 }                                                                              }                                                                                                                                                                                                  
int morph(char *number)  {        

unsigned int intNumber = 0; 
int checkIfPrime = 0; 
checkIfPrime = execvp("/Documents/assignment_4/isPrime",&number); 
printf("%d\n",checkIfPrime);       
if (checkIfPrime == 1) { 
    return 1;        
} else {                 
    return 0;             
}                                                                                           }  

0 个答案:

没有答案