简体   繁体   English

Linux终端文件打开

[英]Linux terminal file opening

This is some code that I wrote but I am confused to how to run it with linux terminal. 这是我写的一些代码,但我很困惑如何用linux终端运行它。 I tried writing like this: asdasd:~/folder/file>./main.c file.txt but I just keep getting permission denied. 我尝试这样编写:asdasd:〜/ folder / file> ./ main.c file.txt但我只是继续获得权限被拒绝。 Do I need some other program to run this with? 我需要一些其他程序来运行吗? I hope I gave enough information to get some kind of feedback 我希望我提供足够的信息来获得某种反馈

(file.txt is the file I am trying to start the program with) (file.txt是我尝试启动程序的文件)

...........
void fileReader(int number, char *vector[])
{
    if(number!= 2)
    {
        printf("File: %s filename\n", vector[0]);
        exit(1);
    }
    FILE *file = fopen(vector[1], "r");
    if(file == 0)
    {
        printf("File cannot be opened\n");
        exit(1);
    }
..........
........

You have to compile the program. 你必须编译该程序。

You do that with 你那样做

gcc main.c -o program

Then you start it with: 然后你开始:

./program file.txt

depending on which Linux OS you're running with (MAC already has this pre installed), just go to the terminal, and change the path to the folder where your program is. 根据您运行的Linux操作系统(MAC已预先安装),只需转到终端,然后将路径更改为程序所在的文件夹。 then do gcc main.c -(any file name that you want, you can even just name this 'main'). 然后做gcc main.c - (你想要的任何文件名,你甚至可以命名为'main')。 then you can just type main, and it'll run your program for you. 然后你可以输入main,它会为你运行你的程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM