PDA

View Full Version : iTerm C++ and stuff




dizzled
Feb 28, 2007, 03:11 PM
Hey everyone,
I am fairly new to programming and Unix but i have a problem that is buggin me a bit. When I open up the terminal (I actually use iTerm, but I don't think there is much difference) I cd into the directory I will be working in. When I compile the executable gets put into the current directory (good) but when I run, my output data file gets put in my home directory (bad). This is very annoying and I can't figure out why it is doing this.

Also, can I make aliases to get me to my frequently used directories. All those cd <directory> commands are annoying. Thanks a lot everyone.



relimw
Feb 28, 2007, 03:36 PM
Hey everyone,
I am fairly new to programming and Unix but i have a problem that is buggin me a bit. When I open up the terminal (I actually use iTerm, but I don't think there is much difference) I cd into the directory I will be working in. When I compile the executable gets put into the current directory (good) but when I run, my output data file gets put in my home directory (bad). This is very annoying and I can't figure out why it is doing this.

Without knowing what the program is, this is almost impossible to answer why it would be doing that. You can try using redirection: cat sometext.txt > here.txt


Also, can I make aliases to get me to my frequently used directories. All those cd <directory> commands are annoying. Thanks a lot everyone.
You can us links, it'll get rid of all those multiple directories you have to type to get places, but you still have to cd :)

ln -s /usr/bin/ mbin
This would drop a link named mbin in your local directory linked to /usr/bin/

lazydog
Feb 28, 2007, 04:38 PM
Hey everyone,
I am fairly new to programming and Unix but i have a problem that is buggin me a bit. When I open up the terminal (I actually use iTerm, but I don't think there is much difference) I cd into the directory I will be working in. When I compile the executable gets put into the current directory (good) but when I run, my output data file gets put in my home directory (bad). This is very annoying and I can't figure out why it is doing this.

Also, can I make aliases to get me to my frequently used directories. All those cd <directory> commands are annoying. Thanks a lot everyone.


Is it a C program? If so you can always use absolute paths in the names of your output files or use the function chdir() to change the working directory.

In Unix you can create soft links to files and directories. To create a soft link in your current directory to another directory or file use:-


ln -s path-to-the-directory

or

ln -s path-to-the-directory some-name-for-the-link


Do a 'man ln' for full details!

Anyway once you've create a soft link you can cd to it, list it etc.

Also, you might find the command line commands pushd and popd helpful.

b e n

EDIT: Sorry didn't read relimw's post fully! Excuse the repitition!
EDIT: Oops, didn't see the C++ in the title!

Eraserhead
Feb 28, 2007, 05:10 PM
I would really use terminal ;), you can also set up aliases by editing the profile folder in your home directory (it's hidden but if it isn't there create one.)

This is mine:


#
# Your previous .profile (if any) is saved as .profile.dpsaved
# Setting the path for DarwinPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH

test -r /sw/bin/init.sh && . /sw/bin/init.sh
alias cdProg='cd ~/Documents/Programming/'
alias matlab='/Applications/Matlab_SV701/bin/matlab -nojvm'
alias sye='cd ~/documents/lecture\ courses/second\ year\ essay'
alias lc='cd ~/documents/lecture\ courses'
alias cprog='cd ~/documents/programming/c\ programming/'


Then I can type cprog in terminal and go to the C programming directory.

dizzled
Mar 1, 2007, 07:23 AM
[QUOTE=relimw;3400476]Without knowing what the program is, this is almost impossible to answer why it would be doing that. You can try using redirection: cat sometext.txt > here.txt

Well, it does it with all of my programs. I have a file pointer and fprintf to the file. Do I need to close the file before I exit? Maybe that is why, that just occured to me. Anyway, I'll play around. Eraserhead, thank you for the profile code, that is exactly what I was looking for.