But, if you don't wanna heed my advice then uh Good luck!
So I got Linux n stuff... now help? :( - Page 2
Blogs > evanthebouncy! |
Jank
United States308 Posts
But, if you don't wanna heed my advice then uh Good luck! | ||
evanthebouncy!
United States12796 Posts
On January 07 2009 18:34 Therapy wrote: Not that linux isn't a fantastic os and emacs a fantastic powerful editor, but I think you should stick to windows while learning C (at least at first). I think you're trying to tackle too many things at once. I would pick one thing to focus on at a time, attempting to learn programming on an unfamiliar os will just slow you down. Not to mention how complicated emacs can be if you want it to be perfect for your use lol. I'd suggest using visual studio express or something first in windows. It'll let you focus more on the programming and will be a lot less overwhelming. But, if you don't wanna heed my advice then uh Good luck! Everyone in my class, or will be in 20 days will be using linux coding in C. I don't think it's that hard or overwhelming. As I said, I'm not completely hopeless. Anyways I just wrote my first program and it printed hello world, awesome! Wish I know how to let it print it 10 times or more, wish I could write a program that could take an input x, that would print hello-world x times. | ||
r3dox
Germany261 Posts
| ||
Jank
United States308 Posts
![]() EDIT: also, On January 07 2009 18:42 evanthebouncy! wrote: Wish I know how to let it print it 10 times or more, wish I could write a program that could take an input x, that would print hello-world x times. int num; printf ("Enter number of super awesome greetings you want: "); scanf ("%d",&num); for(int i = 0; i < num; i++) printf ("Hello World! "); should work fine, I'm not overly familiar with printf/scanf tho as i primarily use cout and cin for console programs (c++ stuff) | ||
evanthebouncy!
United States12796 Posts
On January 07 2009 18:44 r3dox wrote: u have to use ./a.out in order to run a executable Hmm what does ./ do? | ||
Jank
United States308 Posts
well in windows to run a program in console u just type the program name, but in bash on linux the ./ says you are trying to run something in the current directory | ||
evanthebouncy!
United States12796 Posts
| ||
evanthebouncy!
United States12796 Posts
On January 07 2009 18:53 Therapy wrote: well in windows to run a program in console u just type the program name, but in bash on linux the ./ says you are trying to run something in the current directory Then how come emacs work in every directory? | ||
Jank
United States308 Posts
| ||
HeadBangaa
United States6512 Posts
I assume you are not Comp Sci. I'm always excited to see people take up hobby programming! It is sooo enabling. Let's see... I bought that same C book, read a few pages, and never opened it again. Yucky. Ahh shit nevermind. I went over and grabbed this book from my boxes and am looking through it. It's not bad at all. I think I was thinking of a C++ book I bought that was written by the C++ author (yep I checked, I was thinking of Bjarne Stroustrup's The C++ Programming Language). HERE WE GO --------------------------------------------- DISCLAIMER: I AM NOT A LINUX EXPERT, BUT I USED IT THROUGHOUT COLLEGE. I HAVE A BS IN COMP SCI --------------------------------------------- Let's start with your sexy Ubuntu environment. First thing, as a previous poster mentioned, make sure you have the incredible gcc ("GNU Compiler Collection") program installed. Basically, this all-in-one awesomeness will turn a simple text file into an executable program (it "compiles" your hand-written program). An executable on Unix/Linux is suffixed as ".out" whereas on Windows it is ".exe". You should expect gcc to spit out "a.out" (by default; this can be overriden) for any program you compile on Unix/Linux. gcc works for many languages (thus, "all-in-one"). From their page: The GNU Compiler Collection includes front ends for C, C++, Objective-C, Fortran, Java, and Ada, as well as libraries for these languages. In other words, you can focus on the programming (fun stuff) instead of nasty library and dependency mangling. (I won't go into details about the syntax of these commands, but you should read up on sudo and apt-get because this is essential Ubuntu/Linux stuff). 1) Update your Ubuntu installation files and install core utilities, including gcc - open a terminal and enter these commands, one by one: sudo apt-get update sudo apt-get install build-essential 2) Choose a Linux text editor. My favorite is vim ("Vi Improved"), which is a "modal text editor". It is an extended version of vi, an old school Unix editor. My alma mater, UCSD, has a good introduction to vi and a brief addendum for vim. This is the first challenge of programming. Learning how to use a REAL text editor! (the other "classic" alternative is emacs which some of my friends use, but I genuinely hate it. emacs is an editor. emacs is an operating system. emacs is a way of life. emacs is overkill). Spend maybe 1 hour learning vim and you're set for life. It enables you to dominate text files without reaching for the mouse (gvim is a "cheater version" of vim that let's you click with mouse. Defeats the purpose, IMO). Customizing vim is not necessary but very helpful. You can put default settings in your home directory. Just create a file named .vimrc in your home directory (cd ~) and put settings there. Here is my simple, conventional .vimrc file: + Show Spoiler + " HeadBangaa's .vimrc " " 10/2008 -- for Cygwin VIM " fix backspace, and make everything pretty set backspace=2 set syntax=color syntax on colorscheme pablo " set search behavior, ruler, and line numbers set showmatch set ignorecase set ruler set nu " use real tabs of length=4 set softtabstop=4 set shiftwidth=4 set smartindent " set screen size set lines=52 set columns=80 set textwidth=80 3) Open your The [ANSI] C Programming Language (2nd Ed.) book and read pages 5-6 Ok this is a bit lazy of me, but there's no better start, really. To make sure your compiler and operating system are getting along, this walks you through the trivial "Hello, World!" program. One slight alteration: use gcc instead of cc ("cc" is a Unix dinosaur; Linux redirects "cc" to "gcc" anyways.) If you're using vim as recommended: cd ~ mkdir HelloWorld ; cd HelloWorld vim hello.c This will create "hello.c" in a subdirectory of your home directory. I suggest reading the rest of Chapter 1 as well! 4) ...... You've entered the world of C/Linux programming!! YOU FUCKING GEEK~! Got any cool program ideas? | ||
HeadBangaa
United States6512 Posts
looool my entire post is OBSOLETE. You don't have zero experience!!! LIAR!!! | ||
chiflutz
Romania1025 Posts
Also, regarding the path issue, the /bin directory contains the most common binaries (or executables, as it were) of software currently on the system. /bin is in the path environment variable of every user, thus you can run emacs from any directory by simply typing emacs because your shell looks for a binary called "emacs" in every directory within your current path variable. Right, I'm sleepy, I read some more posts. Therapy's code for even more Hello Worlds is right. To search for files/directories from the command line there's the ancient locate tool. You need to run sudo updatedb or sudo locate -u to force a database update, wait a bit until it finishes indexing everything new, then use locate <search query>. New programs are mostly installed in the same place, /usr subdirectories (most software) or /home subdirectories (e.g. your /home/<username> one, the default if you're prompted for an install path or if you're compiling the program from source). The /bin (and, respectively, /sbin) directories actually contain symlinks - think Windows-style shortcuts - to the actual files, with the exact same name. Hope this makes sense to you. Have fun ![]() | ||
0xDEADBEEF
Germany1235 Posts
If you want to have the same behavior as in Windows, do a export PATH=$PATH:. (notice the dot at the end - it stands for current directory, which will thus be appended to the already existing PATH variable). This will just last for the current shell session though - to make it permanent add it to your ~/.bash_profile (or ~/.bashrc if it is executed) - I'm not going into detail on these files, just know that they are automatically executed when you log in (at a shell), so it's some sort of Autorun for the shell. Executables in Linux typically don't have any file extension (think of /bin/ls, /bin/bash etc.) but you could name them however you want to - even ".exe" although that would be confusing because it would not be executable on Windows (because both systems have a different format for executables). gcc names an executable a.out by default but you can change that by just writing e.g. gcc -o exename src.c Recommendation: use no extension or ".bin" | ||
phase
United States399 Posts
This is the first challenge of programming. Learning how to use a REAL text editor! (the other "classic" alternative is emacs which some of my friends use, but I genuinely hate it. emacs is an editor. emacs is an operating system. emacs is a way of life. emacs is overkill). The real reason vi is better than emacs: it was written by someone at UC Berkeley.... and you go to UC Berkeley. hehe. But in all seriousness, I like to use it because it doesn't involve using the mouse at all. You just gotta figure out all the little keys and commands that let you do stuff like search/replace, cut/paste, etc. I picked up vi by just knowing the most basic commands (i to insert, hjkl to navigate when not in insert mode, :w to save, :q to quit, :wq to save and quit, :q! to quit without saving, u to undo, and spamming esc to get out of whatever mode you were in previously), and then if I had to do something more complicated, looking up a hack on google until I memorized how to do it. Basically the list I spelled out in the ( ) is like 90% of what you use in vi. Edit: Also useful for when you code, is creating an .exrc file (with vi as well lol), and in that file type these things: :set number :set autoindent | ||
haduken
Australia8267 Posts
this is obviously not advisable for your own compiled code so yeah unless you declared your own path environ, you need to invoke the binary with a ./ in the front in the current directory. like others have said, you should use gcc and gdb to compile and debug your programs. do man gcc or info gcc... expect to read through a lot of man pages blah blah to geta hang of the common tools. I would suggest you head down to O'Reily 's site and have a look browse through their linux PDFs (Most of their books are open sourced so you can download and read it as a pdf) But honestly, this is all very much info overload for some one starting out. | ||
haduken
Australia8267 Posts
It is so much easier (and free) to obtain tools to learn programming. VI or VIM is so much superior to emac in just about any way possible but apple is apple, orange is orange. | ||
0xDEADBEEF
Germany1235 Posts
On January 07 2009 22:18 haduken wrote: VI or VIM is so much superior to emac in just about any way possible but apple is apple, orange is orange. Uhm, no? :p Both editors are amazingly powerful, and both are also amazingly weird for someone who is used to Windows or Mac GUI editors. Decide for yourself whether it's worth learning one of them - if you already know a bit about Emacs, just stick with it. There's nothing wrong with one or the other except from a personal preference perspective. If you want a more Windows/Mac like editor, I can recommend JEdit 4.3+, or Eclipse as an IDE. | ||
HeadBangaa
United States6512 Posts
| ||
b3h47pte
United States1317 Posts
On January 07 2009 16:29 evanthebouncy! wrote: Thx Tec, my eecs roomate recommended getting a linux for that because he says linux has the more natural compiler and windows has a shit compiler or something haha. Hi Selbon, I use linux just to learn C, I still have windows. The Visual Studios compiler is absolutely fine :| | ||
azndsh
United States4447 Posts
your original question has already been answered, but to summarize very quickly: in linux, the command you type has to be built-in command ("cd", "ls", etc.) or a program in one of your executable folders which is specified by the PATH stuff (most likely "emacs", and tons of other common stuff "top", "less", etc. can be run just by typing their name) "./" simply specifies the current folder you're in. you need need to specify a location to run programs not in the default executable folders (or you can add it to your PATH like people have mentioned though I don't recommend it). basically, you don't need extra permissions to edit stuff in your personal folders, so you can't accidentally run a program and screw yourself over, and the "./" also means that you know you're running a program that's not in the executable folders | ||
| ||