Last Update: 10/26/97 Student Question List ---------------------------------- Answers to questions pretty much appear as I wrote them. Some of the answers here, are references to the answers to other questions to save typing. Email is answered directly -- not 'referenced'. Likewise, questions that start here may become the originator of a FAQ section later. ---------------------------------- 1. If we needed help on fixing bugs in a program, could we and would we take it to you? Yes. That's what I'm here for. You can bring your program, it's bugs and the errors you received to me or to ANY CMSC 106 TA or Instructor. We're all here to answer your questions. We will talk about some common programming errors in class. Individual questions about your specific program should be held until after class or during office hours. ---------------------------------- 2. Just one request: do you know of any Win95 C compilers that will act reasonably close to cc? If so, could you email either the compiler itself or where to get it to me? You can use any compiler you want, just so long as you be certain that your program compiles with the Unix C Compiler (cc), under the -std1 ANSI Standard Conditions. If you want a free compiler that runs on Win95, your best bet is to do a web search for "C Compilers" and "Win95". You might want to add "free". Off hand, I don't know what compilers are available for downloading. Nor do I know which are better than the others (including which are closer to Unix's 'cc'). Just a note about standards. All class projects must be compiled under the -std1 ANSI Standard flag condition. The standard only says what MUST be. It says nothing regarding what can be, and anything that two different compiler companies did differently when the standard was written (and could not be resolved) was Left Out. The standard makes some guarantees, but does not guarantee all C behavior. This is the major reason to be sure and compile, test, and run your program on the Class Cluster Machines. ---------------------------------- 3. How do I use e-mail that in my comp-sci account ? The default UNIX mail programs available to you in your class account are: mail and pine Both of these programs work the same way they work in your wam account. ---------------------------------- 4. How do I to create a file just for homeworks and save them in my directory form the class directory. I think I know how to but could you specify exactly what to do again. Give me what you think you would do, and try it. If it doesn't work, mail me again. ---------------------------------- 5. I'm still a bit confused on why we would develop problems by creating the program on our own computer. I'm planning on writing the first program this weekend. See the Page on "Compiling" and the note about "Standards" in question 2 above. ---------------------------------- 6. What will i need to do in order to get it ready to submit? See the page on "Class Accounts" about submitting and the "Logging in from Home" Page section on "Problems" ---------------------------------- 7. When I log in to my account, it tells me that I have message. Then the prompt changes to "&" instead of "%". Why did this happened? 7.1 If you would please tell me how I can view my message without changing the prompt. The "&" prompt means you're inside the mail program. To leave the mail program and get back to your main UNIX prompt, just type 'q' at the "&". You can't view your mail (ok, you can, but not in any nice, easy, and reasonable way) without changing the prompt. Since this isn't a class in the ins and outs of UNIX, I won't go into the way that you can (besides it's just a BAD idea to do it the other way). There are other mail programs available to you. An easy one to learn with is called PINE (the command to use it is 'pine' all lowercase). You'll get a menu screen when you type it with possible commands and options. It's pretty easy to figure out. Give it a try and send me email or come to office hours if you're still having trouble with it. ---------------------------------- 8. Is this email really for me? Because the email address in the "to" area is also your email address. How can you do that? I sent everyone in the class a Blind Carbon Copy of the same email. I sent the main one to myself so no one would feel that I didn't mean the mail for them. Because I did. Too bad I came up Just Short. You've got good eyes. I don't know how many people noticed that I was in the TO slot. You have to reconfigure pine to give you this capability. ---------------------------------- 9. Okay, lets get back to the project. I started my project yesterday, I finished half of it and it worked. However, I am stuck in number 6, where the program has to ask the user to type in a time. How can you write a program that can input a number? This was a topic for this week's lecture. Let me know if you got the answer to this question during lecture this morning. You might be doing it on Monday. Ask me this question in discussion Monday afternoon. Until then, I don't want to halt your project progress, Give your program variables constant values and "pretend" that you got them from input. I'll also give you a hint: Check your textbook. Chapters 1-3 are the ones being covered for this project. ---------------------------------- 10. The only thing that I need right know is an "A". You've got one. Everyone starts with an "A". Just make sure you study and finish your projects on time so you can keep it. :) ---------------------------------- 11. So far, I know almost all of the material being discussed in the discussion group. It's really kinda frustrating to me because there will be one or two things that I need to know discussed in each class (either getting the name and passwords, or getting the names of the servers that we need to use). I end up going to the discussions and being bored out of my mind. Could you tell me when we're going to actually start with C stuff? Not everyone has seen unix before. I'm glad to have advanced students in the room, that way if I don't have the answer, maybe someone else does. Feel free, I'm glad to have the help. We'll be starting C next week. I just need to mention a few things about compilers and compiling and how to submit your programs. All I can say is stick with it, bring a book, or keep a good eye on me to keep me and my answers on track. The more we stay on topic (instead of going down the myriad of unix paths), the faster we can get to more interesting topics. I'll be keeping a closer eye on the topic track myself. ---------------------------------- 12. Actually I did go through the chfn command. How do I know it worked or in this case didn't work? Does it take some time to register as my having done it? Yes, it takes a while for it to register. Especially if the machines are busy. chfn has a low priority. Check it in a couple of hours and if it still isn't changed, you'll need to do it again. ---------------------------------- 13. PROJECT ONE: I am writing the program for Project1 and in it, it asks that the time that the user inputs to be displayed on the screen along with some other information. For example, if the user inputs 16 03 as the military time, the program is to say something like: 16:03 is 57780 seconds past midnight....blah blah blah. My question has to do with the seconds portion of the time, 03. My program works fine in every other respect except that when a time is entered with the seconds being 9 or less, the display for the time does not print a leading 0. ... How can I print out this 0 placeholder which I only need for 9seconds or less. Since we don't know "if" statements yet, I can't print out the placeholder as a condition of the if statement. And if I use a printf command to just place a 0 in front of the seconds area, then seconds values of 10 or greater will be off by a placeholder. Wow, what a question. Ahh, printf, my old friend. I see a new FAQ Page and Section forming... Until Then: Printf. When you use printf, you use format specifiers to hold the place of the variables whose values you want to print. Different specifiers for different types of variables. To print integers in decimal (base 10) form, you use %d. The format specifier by itself will print the integer directly. No extra spacing, no fancy-schmancy stuff. %5d will print a minimum of 5 digits of the integer. If the integer is less than 5 digits long, it will add extra space to fill all 5 slots. If the integer is more than 5 digits, it won't stop printing your integer at the 5th digit. It will use all the space the integer actually needs. If you leave the '5' out, it assumes a minimum of 1 digit. %5.3d will print the integer with a minimum number of 5 spaces and a minimum of 3 characters. For Example: int i = 13; printf("[%5.3d]", i); Will Print: [ 013] Since the integer i had only two digits, but you specified three characters, it will fill in a leading zero to fill out the three characters without changing the value of the integer i. 013 = 13 Going with that thought: 02 != 2 when used in a format specifier. %02d will print to 2 spaces, and will print a 0 first, if there's only one character in the integer (that is, if your integer has a value between 0 and 9) Whew. Enough for now. ---------------------------------- 14. How do I see the posting account for the class? The posting account for this class is lh106001. You can change to that directory by using the 'cd' or change directory UNIX command. To change to that directory, you type: cd ~lh106001 To change back to your own directory, from ANYWHERE, you type: cd all by itself, or cd ~ the '~' (tilde) character means "home". ---------------------------------- 15. My question is: How do I look into the posted homework for Mr. Herman's class. I'm not sure if you mean, "how do I get there?" or "how do I look at it once I'm already there?" As to "How I get there": Check Question 14. Right above this one. If the question is, "How do I see it, now that I'm there", Here's how to look at it: The unix command that lets you view a file, is called "more". You just type: more [FILENAME] to see the file. For example: to view zippy.c, you'd type: more zippy.c ---------------------------------- 16. I am using Microsft Internet Email, the Mail program came with IE3.2 I could read mail off news.wam.umd.edu but I could not post anything every time I get . Can you help??? I don't use that program to read news. And I don't know much about how to support it. My guess is that it sounds like one of the settings is not quite right. Maybe you don't have the right server name, but I don't know. A better way to find out would be to go to the wam homepage (http://www.wam.umd.edu) homepage and see what it says regarding what the remote-use settings should be. Or, take a break, use 'tin' from your unix prompt and post to 'um.wam' and ask your question there. Or, better still, stop by AITS and ask them. They run the wam computers and know how to support them. ---------------------------------- 17. Is there a difference between a "Literal string" and an "arguement"? My guess is that they are exactly the same since the book definition for literal string is the exact same as the class definition for arguement. I'm not sure what you mean by arguement, but my answer is no, they are not the same. But then, I'm not sure what you mean to be saying. Let's talk about this one in class on Monday. And I'll post the answer here after that. ---------------------------------- 18. When I compile and run this, I get a segmentation fault (core dumped) error after I enter the time. The book has no info on error message. * My program is attached... * My program listing is below... First, DO NOT include your programs in email. Not to me or to anyone else. Error messages are unique to a compiler. So the book can't really deal with them. I'll try and talk about error messages in class, since we have that option. Bring your project and the error message to office hours and we'll figure it out. See the Page on Office Hours to get a complete listing of all office hours for CMSC 106. ---------------------------------- 19. I still do not know where to start with project 1. First read the project description (front page), then take a look at what the output should look like (back page, bottom). What you need to do is create a program that will do this, but with the information you supply. If you're still having trouble getting started, bring what you've got (print it out) to Office Hours tomorrow. See the Page on Office Hours to get a complete listing of all office hours for CMSC 106. ---------------------------------- 20. I've gotten a lot of commands about submit and it working/not working: First be sure that you ran the setup command. If you didn't you are not getting the message of the day every time you login. Did you run the setup command? Type: ~lh106001/bin/setup (If this doesn't work, try: ~lh106001/Bin/setup Check www.glue.umd.edu/~erodgers and the page on submitting programs - class accounts for the right answer if neither of these works. Right now I'm somewhere that I can't use netscape and I don't have the class stuff with me. ) Then submit should work perfectly. After you've run setup, submit works by just typing: submit 1 joe.c where joe.c is the filename you used. The TEXTfile, not the a.out. ---------------------------------- 21. For example, mine works if I enter 16 03 but not if I enter 16:03. The colon messes it up even if a space is included (16 :03). Is this okay? That's perfect. Your program should only accept times entered in the form hours space minutes e.g., 16 03 3 3 16 3 3 16 No colons will be found in the input. You can assume that the input will be correct. ---------------------------------- 22. I used the chfn command to change my finger info but when i checked it nothing had changed. should i go ahead and send in my program or should i wait till the info shows a change? thanks. Absolutely Submit anyway. if you type chfn again and the correct information appears inside the [], then assume the command worked, but has not yet been put into effect by the system. ---------------------------------- 23. Help! What does "ld: unresolved: pringf" mean? Variations of this problem show up pretty regularly Like: ld: unresolved: pringf or ld: unresolved: print in both cases, the problem is that somewhere the word "pringf" or "print" appears where there should be a "printf" If you see this sort of error, check this first. ---------------------------------- 24. In Project 4, for the A, D, E beneath the columns....do we actually have to calculate that in the program or just print it out beneath them? Will we get marked down if we don't calculate it in the program? Even though the data in the table is static and will not change as your program executes, you must calculate these values. ---------------------------------- 25. Yo Liz, never mind the first question I had, I figured that out, but I have a problem in my program. I need to know if this is legal. First: We don't want any formatting/indenting points off: if (stock_name==A){ totA += num_share; row = 0; } Never put the closing brace at the end. It matches the if that opened it and so should be at the same indenting level as that if. Now: the else, being on the same level as the if (an alternative choice for the if) should also be at the same indenting level as that if. Braces on the else should follow the same rules as the ones for the if. For Example: if( traffic_light == Red ){ stop = 1; slow = 1; go = 0; } else if( traffic_light == Yellow ){ stop = 0; slow = 1; go = 0; } else{ /* traffic_light == Green */ stop = 0; slow = 0; go = 1; } Other than that that's perfectly "legal" to make long if else if . . . else if else statement sets. ---------------------------------- 26. I'm running into a spacing problem on project 4. Since I am indenting to use good programming style, some of my printf statements are running off or around the page. Split it into two printf statements. Just remember to get the correct variables in the same printf with the right specifier. ---------------------------------- 27. A SERIES of Related Questions: 27A. Is there any lines of code needed in project 4 for the program to read the file that contains the info?. Check the project description. You can only use features in chapters 1-8. 27B. Can I use FABS from the library to obtain absolute values, or will I loose credit fro this?. You don't need FABS to do the project. You can only use the math.h library if he's discussed it in class. 27C. how do you get rid of a minus sign, example -23.00? Tell me what printf(" %d ", -23.00 ); prints. Then tell me what to change to print 23.00 ---------------------------------- 28. and dow we have to generate the stock print out or can we have 10 printf's? You can just print the table -- there's no calculation there. You have to calculate the Total and the individual statements at the beginning of the output (as shown in the project desc) and the ADE..at the bottom of the table. But you can have as many printfs as you want.. ---------------------------------- 29. What is cat? the UNIX 'cat' command is just like 'more' but it doesn't stop and wait for you to press the space bar when it gets to the bottom of the screen/one page. ---------------------------------- 30. For the table in Project 4, how do we read the table and input the values? Are we going to need about 120 variables or more? The table is an array. Read the Project description to see how big to make it. The table is hard-coded as the initializer list for the table array. All you have to do FOR THIS PROJECT is copy and paste it into the initilaizer list. ---------------------------------- 31. For Project 4, the only thing I'm not sure about doing is how do I keep track of what they enter so I can print out the information later? This is part of what you must figure out to do the project. However, I agree that the project spec is unclear in presenting just how your program is supposed to execute. The Input file "purchases" looks like this: 15 A 5 7 A 3 . . . 0 A 11 Or something similar. Number Letter Number. Some number of unspecified lines. The Only things you can be sure if are 1) There are three values per line and 2) The Last Line Begins with a 0. And this indicates your stopping point. The output described happens as each line of input is processed. That is: Read In: 15 A 5 Process this data Output: $38.70 profit on 15 shares of stock A Read In: 7 A 3 Process this data Output: $7.35 loss on 7 shares of stock A etc, etc, etc stopping once you hit the 0. This is how the program executes. ---------------------------------- 32. just a quick question/ verification, switch statments can't use assignment (ex. case 1 : n = 2;), right ? Sure they can: switch( variable ) { case 1 : n = 2; case 2 : n = 17; default : n = 204; } is perfectly valid. You can put anything you want inside a switch statement. Stylistically, you don't want anything too complicated, but other than that, sure. ---------------------------------- 33. LOTS OF QUESTIONS ABOUT COMMENTS: WHEN TO USE THEM AND WHERE TO PUT THEM: 33A. Hi Liz, I have a question about the comments in the program. On average, how many lines of code have a line of comment ? Do we need to put comments for each line of code ? If not, do we need to write comment for the printf(...) and scanf(...) ? That's not something I can really answer. There are no hard and fast rules. Put them where they make the most sense. Put them where they don't conflict -- visually -- with understanding your code. Remember Comments are used to annotate your code. They're there to aid someone who is reading through it. So if it makes sense to put a simple comment that says: /* Now the program requests data from the user and prints it to be sure it was entered correctly */ when you have several printf's and scanf's that work to that effect, then having the comment is better than not. This way, they only need to read the comment to understand the next several lines of code without having to actually read each printf/scanf -- and have to Figure It Out. Comments should be used wherever the reader would have to 1) decypher CODE 2) Figure Out What's Supposed to Happen at this point in the code 3) Anywhere you think it will help someone who has no experience reading/writing C code read your program and understand what it does. 4) Comments are there to make your code READABLE. Think of it as a formatting issue. Would you find a book without a cover, or a header for each chapter? 33B. Besides, where should we put the comments ? Between two lines of code, or at the end of line ? Think of #4 when you're considering where to put your comments. Comments should go where they don't conflict VISUALLY with your code. Comments are there to make the code Easier to read. Not Harder. ---------------------------------- 34. THE OFFICIAL C FAQ The offical C FAQ has just been posted to comp.lang.c.moderated This is the list of frequently asked C questions that they've compiled over years and years of people asking the newsgroups/classes/&c questions. To read news: Type: tin at your % prompt. This is the "Threaded Newsreader". This should work just as well from your wam account and from your class account. To see all the newsgroups available to you on campus, the command is y for Yank groups in/out. Page down (or search for -- there's a menu at the bottom of your screen) to comp.lang.c.moderated and then press return once you've got that group highlighted. The other way to move in and out of the news groups is to use your arrow keys. The ---> key moves deeper into the newsgroup tree TO THE RIGHT. The <--- key moves you out of the newsgroup tree TO THE LEFT. as shown in the diagram below: Newsgroup ---> Topic List ---> Individual Articles ---> Message Text Newsgroup <--- Topic List <--- Individual Articles <--- Message Text The titles of the FAQ thread are: comp.lang.c Answers to Frequently Asked Questions (FAQ List) comp.lang.c FAQ list Table of Contents comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) If you wish, you can save these messages to your account (read the menu at the bottom to see which key to press to save) and print them out to the CS Printer (You don't want to have to pay to print these they are VERY BIG=LOTS OF PAGES= BIG $$ TO Pay To Print). Remember the CS Printer is free. ---------------------------------- 35. Do we mail you at this address or the wam one or does it matter? It doesn't matter. I have my mail forwarded to one place so I don't miss any. ---------------------------------- 36. I've written my program and it runs and all that but I'm not sure what's considered good style for if/else statements and what isn't. Right now I have something like: > > if () > if () > else() > else if () > else() [&c.. &c... &c...] > What is good style? I didn't think the book was overly helpful in > explaining what is and what isn't and what should be lined up with what > when. Good question. And it's hard to put specifics on it. Indentation helps to show how you mean things to line up. You can use braces (or not) -- to help clearly indicate sets of instructions as well. You can space sets of if-else sets, if that makes it easier to read. Be sure and put comments everywhere you think it might help someone who is reading your code keep track of what's supposed to be happening at that point in it. Good style is all about having someone who is totally unfamiliar with your program, it's specifics, and it's goals, but who can sit down, read through it -- like they're reading a book -- and understand what's happening in the code without having to decypher it too much. ---------------------------------- 37. I used the chfn command to change my finger info but when i checked it nothing had changed. should i go ahead and send in my program or should i wait till the info shows a change? thanks. Absolutely -- Submit anyway. if you type chfn again and the correct information appears inside the [], then assume the command worked, but has not yet been put into effect by the system. You should always submit what you have. ---------------------------------- 38. I did what you showed me and put braces around it, but it's not printing out characters -- just spaces. I do not know what to do? You need to take the next step.. You need to ask: what should have happened and why didn't it? ---------------------------------- 39. Do vars Have to go inside main. I got marked down for putting them above last project. Yes. Otherwise they're what's called "Global Variables".. something, generally speaking, your instructors discourage. ---------------------------------- 40. I was wondering what "%g" is for, the book uses it on pg. 156 %g is for exponent/scientific notation. They explain it in chapter 3. It's only (I think, I don't see an example for scanf) for printf. float var = 839.21; printf("|%g|", var); will print: |8.392e+02| The float in scientific notation. I put the "|" there just so it's very clear where it starts printing the variable and stops printing it. ---------------------------------- 41. I checked my grades from Mars and for CMSC 106 I got a grade "S". What is it stand for? Will we get a grade for every class? S = Satisfactory. They don't do A,B,C.. just S and . . . I don't know what. You should get a grade for every class. ---------------------------------- 42. Two Questions and A Not-So-Happy Answer: An email question: > Was there some problem with tracy today? I kept trying my login > ID and password and it kept saying that it wasn't right, yet it > worked on the other ones.....And It (the system kept closing when > I was trying to get into it) And the related question I got in Office Hours: > The machines are Down. No one's password is working. > Will there be an extension on the project deadline? The machines were not down yesterday. They had too many people logging in to do their projects and rejected some of the logins and did a little freaking out with the passwords because of the overload. Unless Professor Herman said anything different about it in class today, there's no extension. This is one of the hazzards that we mentioned at the beginning of the term. It's also the reason you get two weeks (or more) to complete your projects. If he announced an extension or mentioned it in class today, someone let me know.. ---------------------------------- 43. I just tried to run my program and got the message floating exception (core dumped). I have no idea what this means or what I should be looking for. Core dumps happen for primarily two reasons. However, our C compiler adds a third reason that C usually doesn't support. 1) Division by Zero results in a floating point exception and core dump. 2) Pointer Error. Just because we haven't done pointers yet, doesn't mean they aren't in your program. The "&variable" that MUST be in scanf is a 'pointer'. The "&" must be attached to any variable put in the call to scanf. This is the unusual one that our compiler supports: 3) You have exceeded your array bounds somewhere. This is where I say, "Welcome to C" I say it now, instead of in the very beginning, because here's where you really learn to program -- and where you really learn to debug. The Problem: My Program is having a core dump. aka My Program is (after processess of elimination above) exceeding the array bounds somewhere. The Cure: Throw as many printf statements into your program as you need to track down the problem. Remember: You can remove them later before you submit your final program. Start Big. At every major point, put a printf statment that tells you something about the state of your program at that point. This includes, but is not limited to: 1) the value of all variables at this point. e.g., Row, Col, any Control Variables, and the Table Value you're trying to reach/print 2) any statement about what your program is doing: e.g., "going into for loop", "top of while loop" "Bottom of loop" "Out of Loop", "This choice means that A equaled B", etc, etc, etc... You can use as many statements to get as much information as you want about the program at that point of the execution. OR Simply printf("A"); in one place and then printf("B"); in the next. ... keep on listing printf's and changing the letter so you can trace your program's execution. Debugging and Printf are used to MAKE SURE that your program is doing what you think it SHOULD BE doing according to the Code you *ACTUALLY* wrote. You believe your code does the right thing. Printf statements all over your code should Prove it. And if it doesn't, it WILL tell you just where you went wrong. ---------------------------------- (44.) NEXT PAGE...