Jump to content


  • Posts

  • Joined

  • Last visited

Contact Methods

  • ICQ

Profile Information

  • Location
    New Zealand

Tuxiscool's Achievements


casual (2/7)



  1. Most free tutorials available online tend to be rather poor, but I suggest taking a look at the pages linked to from http://iso-9899.info/wiki/Main_Page, particularly the stuff at http://www.c-faq.com/top.html Also a few extra ones that I like: http://www-128.ibm.com/developerworks/library/pa-ctypes1/ http://www-128.ibm.com/developerworks/library/pa-ctypes2/ http://www-128.ibm.com/developerworks/library/pa-ctypes3/ http://www-128.ibm.com/developerworks/library/pa-ctypes4/ Good luck.
  2. Visual C++ is not a language, but an IDE (Integrated Development Environment) that you may use to compile C++ programs. You can use it to compile executables for Windows. Under Linux/UNIX-based OSs you will want to use g++ (Part of the GNU Compiler Collection, GCC). I disagree about learning C# instead of C++. C++ has a much broader collection of cross-platform libraries available for you to learn and use.
  3. Browse: [About the FAQ Forum] [Table of Contents] [FAQs] [Contribute] [CL: Command Line Questions] CL-09: Compiling C or C++ Programs It is undeniable that the success of the Free/Libre/Open-Source Software movement has largely been due to GCC, the GNU Compiler Collection. Since Richard Stallman -- the founder of GNU -- released The GNU C Compiler to the world in the late 1980s, it has seen many improvements; the support for many many more languages, and a plethora of architectures. After reading this FAQ, you should be able to: Compile C and C++ programs Get the compiler to warn you about stupid mistakes Link your programs with the required libraries. And finally, optimise your binaries. This FAQ will not cover the C or C++ languages, they require their own book! The Compilation Process For compiling C and C++ programs, there are two separate compilers to use, gcc and g++, respectively. Using the famous 'Hello, world!' example (in C) -- hello.c: #include <stdio.h> #include <stdlib.h> int main(void) { printf("Hello, world!\n"); return EXIT_SUCCESS; } We would compile this file into a binary, named 'hello', with the command: gcc hello.c -o hello This command calls 'gcc,' specifying an input file (you can of course have more than one of these 'translation units'), and an output file -- specified after the -o flag -- called 'hello'. Similarly, in C++ -- hello.cc #include <iostream> int main(void) { std::cout << "Hello, world!" << std::endl; return EXIT_SUCCESS; } We would compile this file into a binary, named 'hello', with the command: g++ hello.cc -o hello Very simple, don't you think? Mistakes, and how to catch them We all make mistakes, there's no doubt about that, so having a good way to catch them can make our lives a lot easier. gcc and g++ both provide facilities to do this, the use of a few compiler flags. Both gcc and g++ accept the following flags -W -Wall -ansi -pedantic -W will enable warnings to help protect you against common mistakes. -Wall will enable extra warnings, if you like. -ansi Will make the compiler reject most features that are not part of the ISO C90 standard (By default GNU extensions are enabled.) -pedantic Will ensure strict conformance to ISO C90, giving no mercy for non-standard features. It is typically a good idea to use all of these flags when compiling your programs, they really do help you discover many possible problems with your code. More information can be found within the gcc man page ('man gcc'). To link, or not to link, that is the question If you ever want to make any interesting programs, it is likely that you will need to use the linker to link with the libraries of the APIs that you make use of. GCC provides two main facilities to do this. -l -L Quite intuitive indeed, but what's the difference? -l<libraryname> will search in the default directories for lib<libraryname>.so -L<path> can be used to give an absolute path to the library you want to use, or to add another directory for gcc to search in. A very common usage of -l is to link with the math library in C and C++ programs that use functions from the header <math.h> and <cmath> respectively. To link such a program with the math library, assuming a source file 'program.c', one would issue the command: gcc program.c -o program -lm Easy as that! Optimisation, the double-edged sword? gcc and g++ are optimising compilers, they can be used to increase the speed or size of your compiled binaries. Typically, code that you will be debugging should disable optimisation, but in release-code, you will probably enjoy its benefits. Enabling optimisation is a simple matter, all we need to do is pass an -O (Capital 'Oh'), which has a few main variants. -O0, The default, optimisation-less compile, this is redundant. -O1, Basic optimisation. -O2, More optimisations enabled - this is probably the most-used. -O3, Even more optimisations. -Os, Size optimisations, this may decrease the size of the output binary. Of course, specific details of these optimisations can be found in the gcc man page. I hope you've enjoyed the FAQ, feel free to ask me any questions if you have trouble.
  4. Browse: [About the FAQ Forum] [Table of Contents] [FAQs] [Contribute] [XD: XFree86, desktops, Gnome, KDE...] XD-04: Konqueror FAQ This FAQ will introduce you to some of the neat features available in Konqueror, the KDE Web Browser and File Manager. I will be discussing Konqueror 3.4, found in KDE 3.4, so if you have an older version some of the features discussed here may not be available to you. Tabs Tabs are the greatest thing since sliced bread, they can make browsing multiple pages at the same time simple, and at the same time keep them all easily accessible; another bonus is that they use less memory than opening a new window. There are three ways to open a new tab: Click on the "Location" button on the menubar at the top of the screen and then select "New Tab". Click on the "Window" button on the menubar and then select "New Tab". Press Ctrl+Shift+N Split Views Yet another great innovation, this feature allows you to look at multiple pages in the same tab (If you were wondering, you cannot make more tabs inside a split view.) You can split views Left and Right or Top and Bottom. To do this, click on the "Window" button on the menubar at the top of the screen and then select "Split view Left/Right" or "Split view Top/Bottom" to split the view however you want to, as many times as you wish. The Navigation Panel Last, but certainly not least, I will discuss the Navigation Panel, a feature that you are likely to find useful. To Show/Hide the navigation panel, click on the "Window" button on the menubar at the top of the screen and then select "Show Navigation Panel" or "Hide Navigation Panel", or just press F9. Let the fun begin! You will find tabs here showing: Your Bookmarks System Devices Your Browsing History Your Home Folder The Sidebar Media Player FTP archives and web sites Your Root Folder (A tree view of the filesystem). And the last tab is worth a bit more discussion. Here you will find a highly useful "Audio CD Browser," that you can use to extract music from your CDs to both WAV (Uncompressed) and OGG (Compressed) files; it even downloads the name of each track for you from an online database (freedb). There are also several browsers: A device browser A font browser A LAN Browser A print system browser, which displays connected printers, current jobs, and so on. Of course, there is always more to find in the "Konqueror Handbook" which you can access through the Help menu, or by just pressing F1. Access Keys Access keys are a feature that can potentially speed up your web-browsing (Note that I'm now using 3.5, this may not apply to 3.4). Pressing the right or left 'Ctrl' key while browsing will enable the use of access keys. Access keys map keys on the keyboard to all the hyperlinks contained in a page, so if you press a key associated with a link, Konqueror will follow it. Vi(m) Movement Keys Vi(m) fans may be pleased to know that the vim movement keys, h, j, k, and l can be used for navigation around websites. For those that are not practicioners of Vi(m), these keys correspond to the following movements: h - left (it is the key on the left.) j - Down (sort of looks like an arrow down.) k - Up l - Right (it is the key on the right. I hope you enjoyed this FAQ and most of all that you learned something, thanks.
  5. A segmentation fault occurs when a program tries to access some memory that isn't there. It usually occurs when a program tries to use a file that doesn't exist, so you must be missing something the game requires. Since the error occurs in 10.1 but not 10.0, my guess is that some system specific files are missing, maybe packages that weren't installed this time. Are there any other games which get the same error?
  6. It's the filesystem that controls maximum file sizes and I'm assuming you use ext3 (And i'm quite sure ext3 has a 2GB limit). If so, you may want to consider ReiserFS (Version >= 3.6). More info here.
  7. Tuxiscool

    MDK 10. CE

    I had very much the same problem when i tried installing 3.2 on my 9.2 system. It started at completely random times, sometimes it got further than others etc. It seemed to be a problem with ~/.ICEauthority because i got a few warning dialogs about it, other than that i'm not sure. Hope I was some help. PS: Once I installed 10.0 beta1 the problem was gone.
  8. Without having to get the mplayer codec packages, you could also use Totem, which has support for WMV. EDIT: Then again, you could always use XINE....which totem is based on.
  9. Quoted from Mandrakesoft Wiki pages here.
  10. Sorry that i can't post that FAQ, i do have one, but it has copyright issues. If anyone wants it , i could distribute it individually if you PM me. But there is also a very good resource here: http://kerneltrap.org/node/view/799
  11. Excellent news! And Urza9814, I don't understand what MPlayer cannot do that WMP can. Mplayer has become an excellent supporter or basically all well-known codecs. And is avaliable for people that don't know at www.mplayerhq.hu
  12. Good to know, not that i am surprised though, i've been running 2.6 for a while and noticed very nice speed improvements in Return To Castle Wolfenstein, on a resonably slow (compared to modern standards) Pentium 3 650MHz computer. Most other apps that i use have also gained a speed improvement. The 2.6 kernel and Reiser 4 will make for a nice couple. :D
  13. Just to answer your question in the topic: Programs designed using the Windows API use special "system calls" that Linux does not recognise natively, so what an emulator, like WINE does, is change Windows API system calls into calls that Linux can understand. That's why running programs through emulation will always be slower than natively. Hope that helps.
  14. Browse: [About the FAQ Forum] [Table of Contents] [FAQs] [Contribute] [CL: Command Line Questions] CL-10: Basic Shell Scripting This FAQ will cover basic shell-scripting techniques in BASH (Bourne-Again SHell), the default shell on all (or at least 99%) of all current Linux distributions, and probably for many years this will remain the case. BASH is a very powerful shell, and bash scripting can introduce users to concepts used in all computer programming, which I will talk about briefly in this FAQ. A program is just a collection of instructions to carry out a task. Finding efficient ways to do these "tasks" is what programming is all about. To program in BASH, you need slight knowledge of different Linux terminal commands, as that is essentially all BASH scripting is, instead of writing several commands to do a specific task, you can combine them all so they can all be done through one command with BASH scripts. I will begin with a simple example: Create a file called firstscript.sh, using the command touch firstscript.sh Now open that file with your favourite text editor and type the following code into the file. #!/bin/bash echo "Hello, What is your name?" read NAME echo "Nice to meet you, $NAME" Now save the file. Now, before you can use this program, you must first make the file executable, you can do this like so: chmod 0755 firstscript.sh or chmod +x firstscript.sh Now you are free to run the program, like so: ./firstscript.sh I will go over the different lines of the program, so this will make more sense (hopefully). #!/bin/bash - This tells the computer that the program is a BASH script. echo "Hello, What is your name?" - "echo" prints the contents between double quotes (also known as a String Literal) to the screen read NAME - This line introduces the concept of a "variable", a simple analogy for a variable would be a pocket, it is a storage space which can hold a variety of things, in this case the words entered by the user. In other words, The program stores anything you enter, into the variable NAME, and things can be done with that variable, which will be covered soon. echo "Nice to meet you, $NAME" - The only new content of this line that you haven't seen before is "$NAME", as you may have found out out by running the program, when used with "echo," prints out the contents of variable NAME. The "$" can be interpreted to mean "contents/value of", so with $VARIABLE you would be referring to the contents, or the value, stored in the variable, named VARIABLE . Evaluating expressions Evaluating an expression can be done through the use of square brackets ([ and ]). A simple way to explain this would be through making a rudimentary calculator, so write the code below in your favourite editor and save it as "calculator.sh" #!/bin/bash echo "Finding X * Y" echo "Enter X:" read X echo "Enter Y:" read Y echo "X * Y = $X*$Y = $[X*Y]" You can run the program by making it executable as shown before, and executing it. (./calculator.sh). As you can see, the $[X*Y] returns the value by multiplying the values stored in the variables X and Y. You should take note that if you have many variables, you should use parenthesis '(' and ')' to show the order you want the expressions evaluated. As an example: "$[((X*Y) / (X + Y)) - X]" As you should know from maths, the contents of the brackets will be evaluated first. If and Else Statements If and else statements are useful in the way that you can get a certain block of code to be used only if a condition is true. To show this as an example, make a new file called "ifandelse.sh", you can copy the code from "calculator.sh" to take a slight shortcut, and modify the file to look as it is below: #!/bin/bash echo "Finding the greater number" echo "Enter X:" read X echo "Enter Y:" read Y if test "$X" -gt "$Y"; then echo "$X is greater than $Y" elif test "$X" -lt "$Y"; then echo "$X is less than $Y" else echo "$X is equal to $Y" fi A few new things were introduced in this script, and I'll go over each. The "if" statement - This tests if the "expressions next to it are true, I'll cover these soon. and if thy are true, the code under them will be "used". After that code has been executed, the script continues from after the "fi" statement. test "$X" -gt "$Y" - This uses the GNU command "test" and tests if the value stored in X is greater than (-gt) the value stored in Y. The wonderous semicolon ( ; ) - Like many programming languages, BASH can use the semicolon to separate statements (NOTE: The semicolon is only needed in BASH if you have more than one statement/command on the same line, otherwise it is optional, unlike many other languages where a semicolon is needed to separate every statement.). then - This statement is used after "if" and "elif" (It is not used anywhere else.) to tell it to use the code under the statement, if the condition is true. An easy way to think what this code means if test "$X" -gt "$Y"; then echo "$X is greater than $Y" is "If X is greater than Y, "then" print the contents of the double quotes in the echo statement to the screen. elif - (short for "else if") This tests another condition if the previous condition was found as false, if the previous condition was found as true, this elif statement, and the rest of the code until after the "fi" statement, is ignored. If the condition here is found true, the code below it is executed (as with the "if" statement). -lt - (less than) This is another argument to the "test" command that tests if a the value stored in a variable is less than another. You can find out about the different options that the test command offers you by using the command "man test" else - This is used to test the last condition between the "if" and "fi" statements. As you can see, "then" isn't needed after the else statement. fi - This shows the end of the if/else statements. Looping with "while" statements Usually, "program flow" in a shell script goes in the order "top to bottom". If you want a certain piece of code to be used a certain amount of times, there are a few different statements you can use, this part of the FAQ will cover the "while" statement. The way the computer uses "while" statements is like so: A good example is getting the computer to show you that it can count up to ten. So create a file called "while.sh", and write the following code into it: #!/bin/bash X=1 while test "$X" -le "10" do echo "$X" X=$[X+1] done If you run the script you will get the following output: 1 2 3 4 5 6 7 8 9 10 As you can see, using loops (with "while" statements in this case) is much more efficient than writing 10 different "echo" statements to get exactly the same output. Loops are a very important part of all programming and most programs that you will ever write are very likely to contain at least one loop. As with other examples, this one also introduced new ideas. X=1 - This stores the value "1" in the variable named X, quite simple. NOTE: You cannot have spaces between X and the equals sign ( = ), and the equals sign and 1, otherwise they are all treated as separate statements. while - As said before, this is used like "while condition is true, execute/process code between the "do" and "done" statements. -le - (less than or equal to) Tests if one expression/value is less than or equal to another. do - If the condition in the while statement was true, the do statement shows where to start processing the code. "do" is used with while, until and for statements. (both of which will be explained shortly.) X=$[X+1] - This increments the value stored in variable X by one every time this code is encountered. done - As said before, this shows the end of the "while" statement. Behaves in much the same way as "fi" does for if/else statements. Exercise: Now you can try making a script that counts down from 10 to one using your gained knowledge of shell scripting. If you really want, you can even send me a PM and I'll mark it for you ;). The "until" loop Something that uses the opposite logic of "while", but has the same syntax is the "until" statement which is quite self-explanatory, though i will provide an example anyway. #!/bin/bash X=1 until test "$X" -gt "10" do echo "$X" X=$[X+1] done This executes the code between "do" and "done" until the value stored in the variable X is greater than 10. This script has the same output as the previous example. The "for" loop "for" loops have quite a different syntax from that of "while" and "until" loops. The best way to explain these differences is by example, so create a file "forloop.sh", And write the following code into it: NOTE: The code below contains only my opinion, I mean no offence to anybody whatsoever, if you don't agree with it you can substitute values for your tastes. #!/bin/bash for food in chinese italian korean vietnamese japanese thai cambodian do echo "$food food tastes good" done echo "But indian food does not" I will go over the new parts in this script. for - "for" statements have the syntax "for <variable> in <variable value> ...". I will explain parts of this now. <variable> you substitute for the name of a variable you want to access/use inside the for loop. "in" stores the strings and/or values after it into <variable>. <variable name> are the values or strings that you want <variable> to store. For example, the first time through the last "for" loop, the value stored in the variable food would be the string "chinese", the second time through, "italian" and so on. The value of <variable> is one of the strings/numbers after "in" each time through the loop. The loop finishes when all of the numbers/strings after "in" have been used. If you are confused over what was just said (I wouldn't be surprised), you should run the script and the code should be understood quite easily. The alternative "for" syntax If you have ever come across some programming in C or C++, you are likely to have seen that the syntax of the "for" statement is quite different to what has been shown in the previous examples. This other way of using for loops will be introduced now: for (( i=0; i<10; i++ )) For loops contain three parts, each one separated by semicolons. The format of this is: for ((initialisation;condition;increment)) I will explain each part now: initialisation - This part creates, and sets the value for one or more variables. In the above example, "i = 0" Creates the variable 'i' if not previously created, and sets the value that 'i' contains, to zero. condition - This part tests one or more conditions, just like the if/while statements do. Using the above as an example: "i<10" would test if the value stored in 'i' is less than ten. If it is, the loop will run, if not, the loop will be ignored. increment - This part is used to alter the variable(s) that were previously created. In the previous case "i++", The value stored in 'i' is incremented by one each time the loop has run through. A new thing that you may have noticed is the increment operator (++). This will increment the value stored in a variable by one. There is also a decrement operator that can be used (--), which will decrement a value by one. Time for a proper example of it's use, note that the output will look familiar. for ((i=0, f = 10; i<10, f > 5; i++, f--)); do echo $i;done This certainly isn't the most efficient for loop, but it demonstrates what they can do quite well. It can be "read" as saying, "Initialise 'i' as 0 and 'f' as 10, while 'i' is less than 10 and 'f' is greater than 5, carry out the loop (printing each value of 'i' to the screen) between the 'do' and 'done' statements, and at the end of each "loop", to increment 'i' by one, and decrement 'f' by one." The loop will give the following output: 0 1 2 3 4 The "seq" command This command prints out a sequence of numbers, and as quoted from the "seq" man page, takes these arguments. I'll give an example of each use, even though they are quite easy to understand. seq 20 That would print out the numbers 1, to 20, being incremented by 1 each time. Though if you are wanting the numbers to count up starting from 0, you will need to use the one of the last two formats of the "seq" command, as shown below. seq 0 20 That would display the numbers from 0 to 20, again incrementing by one each time. If you want to change the amount incremented, you will have to use the third format of the seq command, for example: seq 0 3 50 This would display the numbers one through to 50 with an increment of three each time (as compared to the others where "seq" only incremented by 1 each time. Counting down with the "seq" command is also possible, to do this, you would have a negative "INCREMENT", prefixing the number with a "-", like so: seq 400 -20 5 This would count down from 400 with a decrement of 20 until the number 5 is reached, as you will be able to see from these examples, "seq" is very easy to use, and you can find out a little more about it from it's man page. "seq" can be used in your shell scripts like all other commands, and as you may see, is much more efficient than any loop to do the same task. Thanks to aru for telling me about the seq command and the ability of using C's syntax in for loops. If you have any ideas, comments etc. for this FAQ, you can PM me.
  15. do if [ ! -f $imgname ]; then echo $imgname" not found." break fi Using these square brackets means the same as using the GNU command "test". It's saying that if $imgname doesn't exist as a regular file, as opposed to a symlink or whatever, then carry out the instructions between the if statement., i would have thought though that the $imgname part was enclosed in the double quotes, but i am not certain on that. About the rest of the script, you'll have to ask some others ;).
  • Create New...