Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode 如何从Mac上文件夹中的可执行文件运行程序_Xcode_Macos_Terminal - Fatal编程技术网

Xcode 如何从Mac上文件夹中的可执行文件运行程序

Xcode 如何从Mac上文件夹中的可执行文件运行程序,xcode,macos,terminal,Xcode,Macos,Terminal,好了,伙计们,请容忍我,我是初学者。我的教授给了我一个项目,让我在输出文件中键入输入。它在windows cmd中工作,但我在Xcode中运行它,文件打开并工作。但是如何使用终端从其文件夹运行可执行文件呢 这是我的密码 #include <iostream> #include <cmath> #include <fstream> #include <cstring> #include <cstdlib> #define MAX_PATH

好了,伙计们,请容忍我,我是初学者。我的教授给了我一个项目,让我在输出文件中键入输入。它在windows cmd中工作,但我在Xcode中运行它,文件打开并工作。但是如何使用终端从其文件夹运行可执行文件呢

这是我的密码

#include <iostream>
#include <cmath>
#include <fstream>
#include <cstring>
#include <cstdlib>
#define MAX_PATH 99

using namespace std;

void backUp();                //use this to copy the original array
void rowAvg1(int,int);
void rowAvg2(int,int);
void rowAvg3(int,int);
void avgAvg1(int, int);
void avgAvg2(int, int);
void avgAvg3(int, int);
void testAvg(int,int);
void swapLow(int,int);


int grades[5000][5000];  //array to store the original data
int work[5000][5000]; // backup the original data
double Avg1[500];     //to store the average of each student
double Avg2[500];    // average of each student ignoring the lowest two
double Avg3[500];
double classAvg[500];   //to store the averge of the class in each test
char *studentNames[5000];
string sn[50]={"Haris","Leon","Pete","Sam","Tenzin","Shabab","Zakia","Chen","Xiang","Mario","Lawrence","Kyle","Violet","Mary","Paolo","Joseph","Bill","Mario B.","Stephen","Lorraine","Harry","Nicholas","Ivy","James","Kenneth","Manuel","Novak"};

double a1;
double a2;
double a3;
int main()
{
    char filename[MAX_PATH + 1];

    cout << "Enter the filename along with the file format (e.g Grades.csv) :" <<endl;
    cin.getline(filename, MAX_PATH);
    ifstream file("Grades.csv");
    ofstream file2("ClassAverage.csv");



    char line[80], *p; // bigger than the length of a line, p is a string


////// Error check ////////

    if(file.fail()){
    cout<< "File could not be opened. The file name migh not correct." ;
}

    /////////// This loop reads the file line by line, parse it token by token ///////
    ////  and stores each token into a 2d array.   //////////




    int r=0;
    int c = 0;

    file.getline(line,79);

    while (!file.eof())
    {
    file.getline(line,79); // read next line
    p = strtok(line, ", "); // read first token
    studentNames[r]=p;


    if(file.eof())
        break;
    p = strtok(NULL, ", ");
    c=0;
    while (p != NULL) {

        grades[r][c++] = atoi(p);
        p = strtok(NULL, ", ");

    }

        r++;

}

backUp();     //copies the orginal data into work array

testAvg(r,c);    // claculates the average of each column

swapLow(r,c);    // finds and moves the two lowest grades to the end of the array

rowAvg1(r,c);    // finds the over all average grades of each student
rowAvg2(r,c);    // finds the over all average grades of each student ignoring the lowest two grades
rowAvg3(r,c);


//// Finds the average of the averages ////
avgAvg1(r, c);
avgAvg2(r, c);
avgAvg3(r, c);

////// Writes out the data to the file along with the averages /////
file2 << "Names,";

for(int j=1; j<=c; j++){
    file2 << "Test. " << j << "," ;

}
file2 << ",Average ,Avg ignoring lowest 1,Avg ignoring lowest 2" << endl ;


for(int i = 0; i<r; i++){

    file2<< sn[i] << ",";

    for(int j=0; j<c; j++){

        file2 << grades[i][j] << "," ;

    }
    file2<< "," << Avg1[i] <<"," << Avg2[i] << ", " << Avg3[i] << "\n";

}

file2 << "\nCLASS AVG,";

for(int j=0; j<c; j++){
    file2 << classAvg[j] << "," ;
}
file2<< "," << a1 << "," << a2 << "," << a3;  // prints out the average of the class averages and students averages.






file.close();
file2.close();

return 0;
}

////////////////////////////Function Definitions////////////////////////////////////////////

 void backUp(){
for(int r=0; r<5000; r++){

    for(int c=0; c<5000; c++)
        work[r][c] = grades[r][c];
}
}

    void rowAvg1(int x,int y){
int sum;
for(int i=0; i<x; i++){

    sum=0;
    for(int j=0; j<y; j++){

        sum += grades[i][j] ;
    }

    Avg1[i] = (double)sum/y;

}

 }

void rowAvg2(int x,int y){
int sum;
for(int i=0; i<x; i++){

    sum=0;
    for(int j=0; j<y-1; j++){

        sum += work[i][j] ;
    }

    Avg2[i] = (double)sum/(y-1);

    }
}


void rowAvg3(int x,int y){
int sum;
for(int i=0; i<x; i++){

    sum=0;
    for(int j=0; j<y-2; j++){

        sum += work[i][j] ;
    }

    Avg3[i] = (double)sum/(y-2);

}
}


void testAvg(int x,int y){
for(int j=0; j<y; j++){

    int sum=0;
    for(int i=0; i<x; i++){

        sum += work[i][j] ;
    }

    classAvg[j] = (double)sum/x;

}
}

void avgAvg1(int x,int y){

int sum=0;

for(int i=0; i<x; i++){


    sum += Avg1[i];
}
a1= (double)sum/x;
 }

 void avgAvg2(int x,int y){

int sum=0;

for(int i=0; i<x; i++){


    sum += Avg2[i];
}
 a2= (double)sum/x;
}

void avgAvg3(int x,int y){

int sum=0;

for(int i=0; i<x; i++){


    sum += Avg3[i];
}
a3= (double)sum/x;
 }



void swapLow(int x,int y){
int low1,low2;
int temp1,temp2;
int i,j;


    //// Moves the Second lowest to the end

for( i=0; i<x; i++){
    low1 = 0;
    temp1 = 0;
    for( j=0; j<y; j++){

        if(work[i][j]<work[i][low1]){

            low1 = j;

        }
    }
    temp1=work[i][low1];
    work[i][low1] = work[i][y-1];
    work[i][y-1]=temp1;

 }

//// Moves the Second lowest to the end
for( i=0; i<x; i++){
    low2 = 0;
    temp2 = 0;
    for( j=0; j<y-1; j++){

        if(work[i][j]<work[i][low2]){
            low2 = j;

        }
    }
    temp2=work[i][low2];
    work[i][low2] = work[i][y-2];
    work[i][y-2]=temp2;


}
 }
#包括
#包括
#包括
#包括
#包括
#定义最大路径99
使用名称空间std;
无效备份()//使用此选项复制原始阵列
无效行avg1(int,int);
无效行avg2(int,int);
无效行AVG3(整数,整数);
void avgAvg1(int,int);
void avgAvg2(int,int);
void avgAvg3(int,int);
无效测试vg(int,int);
空耙(int,int);
国际等级[5000][5000]//数组来存储原始数据
整数工作[5000][5000];//备份原始数据
双Avg1[500]//存储每个学生的平均值
双Avg2[500];//忽略最低两名学生的每个学生的平均数
双Avg3[500];
双类平均值[500]//存储每个测试中类的平均值
char*学生姓名[5000];
字符串序号[50]={“Haris”、“Leon”、“Pete”、“Sam”、“Tenzin”、“Shabab”、“Zakia”、“Chen”、“Xiang”、“Mario”、“Lawrence”、“Kyle”、“Violet”、“Mary”、“Paolo”、“Joseph”、“Bill”、“Mario B.”、“Stephen”、“Lorraine”、“Harry”、“Nicholas”、“Ivy”、“James”、“Kenneth”、“Manuel”、“Novak”};
双a1;
双a2;
双a3;
int main()
{
字符文件名[最大路径+1];

嗨,凯尔,我不确定,但从你的截图上看,这是一个“总线错误”——这可能与(OP说他的程序在Linux上运行良好,但在Mac上运行不好)有关。这可能是一个未定义的行为,在一个系统上神奇地工作,但在另一个系统上却没有“总线错误,乘客被甩了”。您需要在调试器中运行代码。从终端,
cd~/Desktop;lldb name_of_program
。首先感谢大家的回复,它是在windows和@特洛伊木马上运行的,所以键入cd~/Desktop“11db”那么我的程序名是什么?嗨,凯尔,我不确定,但从你的截图上看,这是一个“总线错误”——这可能与(OP说他的程序在Linux上运行良好,但在Mac上运行不好)有关。这可能是一个未定义的行为,在一个系统上神奇地工作,而不是在另一个系统上“总线错误,乘客倾倒”。您需要在调试器中运行代码。从终端,
cd~/Desktop;lldb name_of_program
。首先感谢大家的回复,它是在windows和@特洛伊木马上运行的,所以键入cd~/Desktop“11db”,然后键入我的程序名?