LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-18-2006, 09:22 PM   #1
circuit_girl
Member
 
Registered: Sep 2006
Posts: 35

Rep: Reputation: 15
Multiple Errors in C program (beginner)


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
 
Old 09-18-2006, 10:11 PM   #2
Leisy
Member
 
Registered: Sep 2006
Location: Brno, Czech Republic
Distribution: Fedora
Posts: 56

Rep: Reputation: 15
don't close \n in quotes, then it seems to work besides system("history");

btw. the error message Badly placed ()'s gives good clue
 
Old 09-19-2006, 12:18 AM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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):
Code:
gcc -Wall -o new_prog new_prog.c
./new_prog
 
Old 09-19-2006, 01:23 AM   #4
circuit_girl
Member
 
Registered: Sep 2006
Posts: 35

Original Poster
Rep: Reputation: 15
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?
 
Old 09-19-2006, 01:42 AM   #5
circuit_girl
Member
 
Registered: Sep 2006
Posts: 35

Original Poster
Rep: Reputation: 15
I put all of the command in and it said
gcc: ./file_name: No such file or Directory

thank you for all the help so far
 
Old 09-19-2006, 01:53 AM   #6
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You use ./filename to run the program, i.e. it's not part of the line you use to compile.
 
Old 09-19-2006, 03:08 AM   #7
circuit_girl
Member
 
Registered: Sep 2006
Posts: 35

Original Poster
Rep: Reputation: 15
what does the -Wall stand for. I did not understand the man for it
 
Old 09-19-2006, 03:35 AM   #8
circuit_girl
Member
 
Registered: Sep 2006
Posts: 35

Original Poster
Rep: Reputation: 15
It is working Thanks to everyones help I just have a couple of questions:

1. How come it will not execute with out typing that wall command and what does the -o stand for?

2. What does the ./ stand for when I try to execute it.

3. Why do I have to do it everytime I enter Unix?

Thanks Again
 
Old 09-19-2006, 03:43 AM   #9
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
-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.
 
Old 09-19-2006, 03:47 AM   #10
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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.

Last edited by jschiwal; 09-19-2006 at 03:51 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple SCSI errors.... raid517 Linux - Hardware 1 10-21-2004 06:52 PM
Apache and multiple UserDir errors bai_design Linux - Networking 2 08-31-2004 04:14 PM
Multiple errors in config.log after ./configure for GLIB 2.4.4 eckerww Linux - Software 0 07-22-2004 10:55 PM
Madrake Linux, Multiple Errors Me Only Linux - Hardware 2 03-23-2004 04:04 AM
Ouch! Multiple errors on boot up... raid517 Linux - Software 3 06-29-2003 07:14 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration