ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am just learning how to use unix and program in unix. I have programmed before but it has been awhile.
The first thing I am trying to do is run a c program that will excecute unix commands and will display some comments on the screen.
#include <stdio.h>
#include <stdlib.h>
main()
{
printf ("Getting something to print out.'\n'");
system ("ls");
system ("pwd"); /*prints working directory*/
system ("history"); /*prints the history of commands*/
return 0;
}
I have figured out that you have to compile and run it with 2 diffent commands.
I can comile it but it will not run I get an error
/TT_DB: No match.
/TT_DB: No match.
/TT_DB: Permission denied.
Badly placed ()'s.
%
What am I doing wrong? PLEASE HELP
The code works as-is on my system, albit probably not as intended (referring to the single quotes and the \n Leisy mentioned). I'm willing to bet there's a problem with the commands used to compile and/or run the program. Here's hat I think is going on:
You have a script on your system with the same name as the executable you're trying to make
The script is located somewhere in your PATH environent variable
When you try to run the program (after compiling), you aren't giving the path to the newly compiled executable
To be certain, you need to post what commands you are using to compile the program and the command you're using to run the program.
In case I'm right, here's the customary way to compile and run a program (assuming the source file is named new_prog.c):
I tried using that code, I got the same error messages. I also do not get a little of what you said. the second line that you entered, ".\new_prog" do I put that at the end of the command?
-Wall gives you all warnings about things that could be wrong with your code. In gcc's man page, there's quite a long list of things that you can be warned about. I couldn't be bothered to read it all, to be honest.
You need to use ./filename if . (i.e. the current directory) is not in the $PATH environment variable. When you run an executable, the shell searches all the directories listed in $PATH and if that executable isn't in those directories, you'll get a "command not found" error. "./filename" just tells the shell to run the executable filename that's in directory . (again, the . stands for the current directory). A similar example would be if you had a directory called Programs in your current directory. If you wanted to run an executable in that directory, you'd use Programs/filename.
1. The -Wall options enables warnings. It should compile and run without it however you may miss problems in your code if you don't use it. The -W part is for Warning, and "all" is to enable all warnings. This is easier than manually enabling dozens of warnings.
2. The current directory isn't in your path, so to execute code in the current directory, precede it with ./. to indicate that the program is in the current directory. You don't want to add the current directory "." to your path. This is to prevent executing a hackers version of a common command such as "ls" or "dir" in a world writable directory such as /tmp.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.