Wikipedia:Reference desk/Archives/Computing/2012 October 17
Computing desk | ||
---|---|---|
< October 16 | << Sep | Oct | Nov >> | October 18 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
October 17
VERY basic C Questions I can't find online!
Hi, I have experience with Javascript and am trying to jump into C, but I am finding some problems before I even start!
First of all, is C like Javascript in that I can just type my code into notepad? If so, what then? Do I save it as a .something file and run it in firefox? Or is there some other completely different process to even viewing the result of C code?
I'd appreciate an answer as soon as possible, and I'll be asking more questions once this one is answered! Thank you!169.231.8.73 (talk) 07:02, 17 October 2012 (UTC)
- C is a compiled language, so you must save as a *.c file (or *.cpp or *.c#, for variants), then compile that file, which generates an object files (*.o). Those object files and libraries are then linked together to form an executable (*.exe file), which you can run. There are free compiler/linkers out there, such as GCC. There also might be interpreters out there which can run C source code directly, but those aren't the norm. StuRat (talk) 07:08, 17 October 2012 (UTC)
- Sorry, but I need more help. I reached here, then here, thenhere, where I downloaded gcc-4.7.2.tar.bz2 I have no idea if this was the right thing to do, but now my computer tells me it doesn't know what program to open it with. Help me with figuring out how to get the compiler to a useful state?169.231.8.73 (talk) 10:05, 17 October 2012 (UTC)
- GCC is usually used in UNIX/Linux environments. The file you downloaded is probably for one of those, and is possibly source code that needs compiled as well. There are pre-compiled Windows version available with Cygwin and MingW - you can find links [1]. (A compiled program is called a binary) However, you may be better off downloading Visual Studio C++ Express Edition. It is a C++ compiler, but aside from a few minor differences C is a subset of C++. It will give you a nice editor, compiler and debugger all integrated into a simple interface.209.131.76.183 (talk) 12:10, 17 October 2012 (UTC)
- Sorry, 169, but compiled languages like C are very different from interpreted languages like Javascript, and you don't yet have enough clue to understand the answers to the questions you are asking. I strongly recommend that you find a basic introduction to C to read -- you can find a number online, such as http://www.sis.pitt.edu/~ir/KS/Data/RMiles/contents.html. Looie496 (talk) 14:45, 17 October 2012 (UTC)
- I tend to agree with Looie496's assessment. At my undergraduate college, before any engineering or computer science student was allowed to take a programming class, they were required to pass the Introduction to Computing course material. You may find thefree online text very helpful. While this frustrated many students who believed they were "computer experts" - myself included - this simple class presented a formal introduction to material that is absolutely essential to understanding how a computer works. You must master these concepts before you attempt to program in a language like C. Before you understand these fundamentals -things like the way file systems work; or the role of the operating system in mediating software- and hardware- access - the best you can do with the C language is to copy-and-paste other people's code (and build-scripts); that approach has very limited utility in teaching you, or in getting useful work done. Nimur (talk) 17:31, 17 October 2012 (UTC)
- [2] takes you through the steps of installing Code::Blocks and running a simple "hello world" program. I've never used Code::Blocks, but the page makes it look like a pretty good place for a beginner to start. That site also seems to have a bunch of tutorials aimed at beginners. (I'm working under the assumption you're running Windows. If not, let us know what you are using.)209.131.76.183 (talk) 17:33, 17 October 2012 (UTC)
- Some follow-ups:
- 1) Are you on Windows ? If so, what level ? XP ? Vista ? Windows 7 ?
- 2) I disagree about needing a class before moving from an interpreted language to a compiled language. It actually is more difficult moving the other way, IMHO, as then you have to worry about defining functions before you use them, etc. You might want to start with a "for idiots" book (no offense, I use them, too).
- 3) However, C is a rather unpleasant language, and is more difficult to learn than many others. BASIC might be an easier starting point.
- 4) While you can use any old text editor to write source code, there are also editors customized for computer languages which will do things for you like highlighting incorrect syntax. Those can be quite helpful. StuRat (talk) 18:29, 17 October 2012 (UTC)
- I agree with everything you say except the suggestion to learn BASIC. Dijkstra put it well: the teaching of BASIC should be rated as a criminal offence: it mutilates the mind beyond recovery.[3]. And the same goes for that pit of insanity they call PHP. For heaven's sake learn Python or something else structured! Marnanel (talk) 20:19, 17 October 2012 (UTC)
- I'm learning Python now, and it has some annoying, unnecessary complexities, like arrays starting at zero. And one thing it has that I find rather unstructured is implicit variable definitions. In FORTRAN, I always use the line "implicit none" at the start of each program and subroutine, to force me to think through the exact definition of each variable. Python also allows global variables, which is about as unstructured as you can get. StuRat (talk) 20:39, 17 October 2012 (UTC)
- Any programming language that isn't a toy defaults to arrays starting at zero. Using one-based arrays is a foolish concession to foolish programmers which fills anything more than trivial uses of array indexing with endless minor adjustments, and I note that since the OP is experienced in JavaScript they won't have a problem in that direction anyway. And (let me make sure I understand) are you actually criticising Python's ability to use globals while simultaneously suggesting the serious use of BASIC? Marnanel (talk) 20:48, 17 October 2012 (UTC)
- My point is that you might as well start with an easier language, if neither BASIC nor Python is well-structured. Also, FORTRAN is a serious language and defaults to 1. The idea is to make it more closely aligned with how human's count, rather than how computer's count, to make it easier to use. When human language changes so you say "my zeroth transaction today was...", then it will make sense to program that way. Until then, the computer should figure out that array element 1 is at memory offset 0, so the programmer and end user don't have to concern themselves with such trivialities. StuRat (talk) 20:54, 17 October 2012 (UTC)
Thanks for the help guys, but so far I'm still pretty clueless :(
My assignment is this. I cant even figure out how to get something on my screen that lets me write C code. Code::blocks doesnt seem to be working. And is there a way to view the source code of the drawings already submitted?169.231.8.73 (talk) 23:18, 17 October 2012 (UTC)
- A) That says you are to use GCC under Linux. Are you even on Linux ? Don't they provide instructions on how to install GCC ? If you're not on the Linux operating system, then you either need to get that or use one of the Windows versions of C compilers listed above. However, that would mean the instructions given in the class won't always apply directly, since you aren't using GCC. So, perhaps getting some version of Linux would be easier. Don't they give instructions for doing this at the start of the class ?
- B) It also says completing labs 0-7 is a pre-req. Did you do those ?
- C) I expect that such a class would have included detailed instructions on how to set up the environment.
- D) They are using a "make" command to compile and link together (this uses the "Makefile" provided).
- E) It says you're supposed to have a partner. Do you ?
- F) As far as writing code, as I said, any text editor will work. For this project, you're supposed to edit the file "ourDrawing.c", which they provide. If you use the Linux operating system, it won't have Notepad on it, but will have similar text editors.
- G) I don't know what "Code::blocks" means. Can you explain ? StuRat (talk) 23:47, 17 October 2012 (UTC)
- Hi, OP. You need to follow the step-by-step instructions closely. You need to be on computer with an installed C compiler, in this case gcc, ie one where typing gcc --help will produce some bumph on the screen. For this project you also need make, which chains together the calls to gcc from something called a makefile, saying "if you've not got this do that". Installing gcc and make are hard, probably impossible if you've never used them. Your instructor has provided an installation on your departmental machine, you should use it. When you've had a bit of success with that, by all means have a go on your own computer. Departmental admins spend a lot of time getting machines with the right stuff on them and while shared machines may seem like an evil communist plot and a bit skanky, they're the way to get things done until you're able to manage your own machine. Use notepad in this case to edit the c files. There's stuff that's prettier but that will just add to things to go wrong at this stage, just concentrate on getting this example going. A C-program takes files ending .c and .h and turns them into .o's and then globs them all up into an executable. An executable is an application just like a browser is or a game is or a CD ripper is. It's nothing particular to do with the web. You run it from the command line as mentioned in the documentation by typing the executable name. In this case it seems to generate GIF files. You can view them later with a browser but that's not the point: the point is that this software makes them. The examples are goofy but it could easily be a fractal or a ray trace with only a little more work. As other people write above, C is difficult to write. It's good for a few things. First, it's very, very quick (if written well). Second, it can access the underlying system with unparalleled accuracy and precision. Third, it teaches you about how systems work. There are /a lot/ of C jobs out there, it's well worth learning for itself and for what it teaches you about how stuff works: this isn't your teacher being old-fashioned or random. You almost certainly won't understand other languages as well, or see where things like performance problems are coming from until you've learnt C. It's worth sticking with, even if it takes a long time to do not so much. For now, follow the instructions you linked to. For example, open notepad and write in a file called hello.c.
#include <stdio.h> #include <stdlib.h> int main(void) { puts("Hello World!"); return 0; }
- Now run this command on the command line
gcc hello.c -o hello
- Now run the application you just made from the command line
./hello
The OP has linked to his assignment instructions, which clearly state the required prerequisite knowledge: "Before starting this project, you should have completed the labs up through lab07. In particular, you should be comfortable working with arrays, structs, arrays of structs, and passing structs and arrays of structs to functions." Have you completedLabs 0 through 7? If you expect to start at Step 8, without completing Steps 0 through 7, you will never be a very good programmer: programming is about exact adherence to procedure; or rather, the definition of exact procedural steps so that a dumb-machine can follow these instructions. Creative use of procedure can only really be achieved after you've got the basic technique mastered. Nimur (talk) 01:30, 18 October 2012 (UTC)
- The due date for the assignment is March 11, 2010. I imagine the original poster just found it online and thought it would be a good starting project. (Which it probably isn't.) -- BenRG (talk)
The professor who assigned this to his class in March 2010 is my professor now, and he is asking that everyone in class complete this lab to gauge everyone's prior knowledge. The original prerequisites and everything are not part of this course, this is our first assignment of the quarter. So I do not have any of these things already, I am attempting to finish this completely by myself. I have a meeting with the professor tomorrow, it's possible I might have to drop the class if I cannot complete the first assignment :( I've spent every minute of free time these past three weeks trying to learn this too... 169.231.8.73 (talk) 03:55, 18 October 2012 (UTC)
- We really would like to help you, but we need you to start answering our questions. The first is if you have access to a computer with some variant of the Linux operating system on it. Do you ? StuRat (talk) 04:14, 18 October 2012 (UTC)
- I do. It's at the computer lab, though I won't be able to get into the computer lab until tomorrow morning. Once that happens I plan to try to use what 81.141 suggested. I also have an account that will allow me to upload the project once (if) I finish it. I apologize for being slow and overwhelmed, it's just that a lot of this is unfamiliar to me. (And Code::Blocks was something I downloaded because of 209.131's suggestion. It looks fine, but not for this project, because it seems to only have a CLI, and I need to output a picture.)169.231.8.73 (talk) 04:23, 18 October 2012 (UTC)
- OK. Now, do you know if the Linux computers in the computer lab have GCC on them ? (The "Hello World" test will tell you for sure.) If not, are you allowed to download and install it on them ? And when is this project due ? StuRat (talk) 04:26, 18 October 2012 (UTC)
- First of all, the assignment is not really about the mechanics of C programming, building the program or making it run successfully. That is something you really should have learnt in previous classes/labs. If you didn't attend those classes/labs, you are going to be pretty stuck just jumping straight in with this assignment. What the assignment is about, is the logical thought processes behind developing a program to make it do what the requirements ask for. You are expected to use your previous knowledge and the provided building blocks to make the program draw a simple image at different sizes and positions. I suggest you go see your professor as soon as possible and explain that you are fining getting started on this assignment particularly challenging because you have no C programming experience. Then ask for his suggestion as to what you can do next. Astronaut (talk) 11:52, 18 October 2012 (UTC)
- On the plus side, if you install a reasonable modern Linux distribution on your computer, and select "Development System"/"Developer Workstation" or similar at the SW configuration stage, it will almost certainly install all tools (gcc, make, text editors,...) that you need automatically. Installing Linux instead of Windows (losing all your old data!) is easy (if you have a Linux distribution that is somewhat more recent than your hardware, so that it can detect the hardware automatically). Installing Linux in addition to Windows is somewhat more tricky (and risky - backup first!). --Stephan Schulz (talk) 13:09, 18 October 2012 (UTC)
- Installing it on a USB flash drive instead of the hard drive is a lot safer. That way you just unplug the flash drive and reboot to get back into Windows. StuRat (talk) 02:52, 19 October 2012 (UTC)
- Indeed, your are right. I'm too old ;-). But IIRC right, at least Ubuntu and Fedora have
lifelive images for CD/DVDs and USB sticks that you can boot from and use without any installation (in the CD/DVD case, I think user data is written to the Windows file system). --Stephan Schulz (talk) 06:04, 19 October 2012 (UTC)
- Indeed, your are right. I'm too old ;-). But IIRC right, at least Ubuntu and Fedora have
- Also live images. :-) StuRat (talk) 06:40, 19 October 2012 (UTC)
- There is a reason it says "near native" in that language box on my user page ;-). --Stephan Schulz (talk) 08:51, 19 October 2012 (UTC)
- After an entire lifetime speaking English, I've achieved a near native mastery, as well. :-) StuRat (talk) 05:18, 20 October 2012 (UTC)
- If you have spend your entire lifetime speaking English, how do you get anything else done? And doesn't it keep you awake at night?--Stephan Schulz (talk) 06:32, 20 October 2012 (UTC)
- After an entire lifetime speaking English, I've achieved a near native mastery, as well. :-) StuRat (talk) 05:18, 20 October 2012 (UTC)
So I spoke with the professor, and he has agreed that I may not be ready for this lab. He has worked with me to create a program that caters to my current needs and skill level, and this drawing assignment is now my final project. So thank you all for your help, I can see that I'm not ready for this assignment just yet. I've saved everything you all wrote in a document, and I will peruse it if I need help, or I may just create a new section in this reference desk; this one is getting dangerously close to the top of the page. Thank you all, and I've passed out barnstars to the particularly helpful members! 169.231.8.73 (talk) 21:59, 20 October 2012 (UTC)
- You're quite welcome. StuRat (talk) 18:04, 21 October 2012 (UTC)
![](http://upload.wikimedia.org/wikipedia/en/thumb/f/fb/Yes_check.svg/20px-Yes_check.svg.png)
openoffice calc - graphing "wild" data
I've been asked to graph weekly hit stats for our website. Most of the time, the range of the data is 0 to 500, however we had two weeks where the hits were in the 2000-3500 range. This makes most of the graph very difficult to see as it is so small. What would be the best way to graph this data so that all the data is visible? Is it possible to have two different scales on the y-axis, with 0-500 taking up the bottom 3/4's of the graph so the data is visible and the rest of the axis in a small scale to show the bigger numbers? Thanks! --TrogWoolley (talk) 13:40, 17 October 2012 (UTC)
- You might want to try plotting on a logarithmic scale. It should be an option for the chart axis.209.131.76.183 (talk) 13:48, 17 October 2012 (UTC)
- Are you sure about those figures? You should normally exclude robots, plus as well as the normal probes for weaknesses every so often sites get some hacker trying out all sorts of stupid things on it. But I agree if you are having sudden surges of interest then a logarithmic scale is what you want. But then again it may be right just to have the rest go invisible if you wnat to show the actual amounts overall. Dmcq (talk) 14:53, 17 October 2012 (UTC)
- What information do you want a person who looks at the graph to be able to pick up from it? Looie496 (talk) 14:52, 17 October 2012 (UTC)
- Another option is to put a break line (doesn't Wikipedia have an article on this ?) in the tall bars in a bar graph, and write the number above them. I don't know if OpenOffice supports this, however. StuRat (talk) 20:46, 17 October 2012 (UTC)
- Thanks for the suggestions. A break line would be an ideal solution and I had already fudged this by capturing the graph and manipulating it using a graphics package. There appears to be to no method to create a break line in calc. However I found that you can create graphs with two y axis and they can have different scales. Problem solved!. --TrogWoolley (talk) 09:28, 19 October 2012 (UTC)
- Great, I'll mark this Q resolved. StuRat (talk) 18:01, 19 October 2012 (UTC)
![](http://upload.wikimedia.org/wikipedia/en/thumb/f/fb/Yes_check.svg/20px-Yes_check.svg.png)
Torrent Download Problem
While downloading a torrent file , it just shows " connecting to peers " , and the download doesn't begin . How do I resolve the issue ? — Preceding unsigned comment added by Jug9 (talk •contribs) 14:17, 17 October 2012 (UTC)
- The only possibility is to use a different Bittorrent program, but that probably won't work. It is impossible to download a file if your program can't find a peer who will provide it to you. Looie496 (talk) 14:37, 17 October 2012 (UTC)
Try another port. Many tracked torrents also are entirely unseeded. ¦ Reisio (talk) 17:05, 17 October 2012 (UTC)
- It would be worth trying to find out whether the trackers think there are seeders; whatever site you got the torrent from ought to say, somewhere. If there are no or very few seeders then it's possible there may just not be any peers to connect to. If there are lots of seeders and you still can't connect, you will need to troubleshoot your client and/or your router and firewall settings. But not knowing your torrent program, your OS, or anything else about your situation, it's not possible for us to give any really specific debugging information or suggestions for you. There are just too many possibilities. --Mr.98 (talk) 22:46, 17 October 2012 (UTC)
css nonsense
Hi, I have the following code in my css sheet:
div.selectorFormSection.override { font-size: 20px; }
Only problem is, it is constantly being overridden by something in jquery ui:
element.style { font-size: 16px; }
I've checked with Firebug, and my code is definitely present, it's just getting crossed out. Now surely my own rule is more specific, since it has two classes. As I understand it, for the style rule to be applied, an element must have both classes. That makes it more specific than the jquery rule, which only has one class. I don't want to have to write junk like "!important" every time I do something simple, so please, can someone tell me what's wrong with my code? Thanks, IBE (talk) 23:51, 17 October 2012 (UTC)
- element.style in firebug isn't really a CSS selector. It means that this content was inside a style element on the tag in the HTML or has been added as if such by javascript (more likely). Something in jQuery UI is going in there and explicitly setting the font-size to 16px. It's usually easier to use themeroller to roll a jQuery UI theme with the correct sizes in them than to argue with it over particular tags.81.141.91.145 (talk) 23:59, 17 October 2012 (UTC)
I see. Since it's my own html, I'm pretty sure it's the second option: javascript. I've been wondering about this irritating "element.style" for the longest time, so very glad I asked. I won't put "resolved" in case someone has more to add, such as suggested workarounds, but that pretty much solves it. IBE (talk) 00:06, 18 October 2012 (UTC)