I'd like to know how to put the name of the txt file in the c language code when you run it, not specify the file name.

Asked 2 weeks ago, Updated 2 weeks ago, 2 views

Even if I try to google it, the terms in the question are not correct, so I'm asking you because only information that is different from the information I want to find.

After coding from putty to c language, I would like to know how to execute it by putting the name of the txt file instead of specifying the file name with fopen in advance when executing the code using the txt file. For example, ./test.c input.txt I want to run it like this, but I can't find a way.

putty c

2022-09-20 13:13

1 Answers

The test.c is a source file and cannot be run like ./test.c.

After you create an executable by compiling the test.c file with a compiler such as gcc, you must run the executable file.

gcc -o test test.c

Compiling as above creates an executable file named test.

You can then run the executable file as shown below.


And if you want to do something like ./test input.txt, you need to write a program accordingly by passing the string input.txt inside the program through "command line argument"

Search Google or Naver for C language command line arguments or command line arguments to check how to use them.

2022-09-20 13:13

If you have any answers or tips

© 2022 pinfo. All rights reserved.