Computer Science Canada A couple of questions about C? |
Author: | php111 [ Fri Jan 02, 2009 11:03 pm ] |
Post subject: | A couple of questions about C? |
1.) Would anyone refer C Primer Plus 5th editions for beginners? 2.) The reason why I stopped with C is because I refuse command line. I wasn't understanding it. I found it to hard. I gave up on a member in PM on here. He offered to try DrScheme, and a couple of others for GUI. I would really like to stick with one GUI app. Would DrScheme be good to learn from? 3.) What is a list of books to read and learn to understand C, starting from the basics to advanced? Like when would C Complete Reference would come in? 4.) What is the full name for the K&R book? I am aware it's honestly not to learn from. It's the writer or maker of C. I would like to know what is the full name of the book. Thank you if someone can answer all 4 of my questions. |
Author: | Vertico [ Fri Jan 02, 2009 11:52 pm ] |
Post subject: | RE:A couple of questions about C? |
2. Take a few days to learn how to use command prompt. It may seem daunting at first, but when you get to know it, you'll begin to like it. Also, you could always considering moving over to Linux, but that another story. 3. The only C book I have is called "A book on C". It starts from the very beginning and moves all the way through. I would recommend it. |
Author: | php111 [ Fri Jan 02, 2009 11:59 pm ] |
Post subject: | Re: RE:A couple of questions about C? |
Vertico @ Fri Jan 02, 2009 11:52 pm wrote: 2. Take a few days to learn how to use command prompt. It may seem daunting at first, but when you get to know it, you'll begin to like it. Also, you could always considering moving over to Linux, but that another story.
3. The only C book I have is called "A book on C". It starts from the very beginning and moves all the way through. I would recommend it. I tried the command line. I really don't like it. Would you recommend DrScheme, or something else? |
Author: | wtd [ Sat Jan 03, 2009 12:41 am ] |
Post subject: | RE:A couple of questions about C? |
Ironically, DrScheme gives you another command-line of sorts in the form of its REPL (read-eval-print-loop). But yes, Scheme is an awesome learning tool. |
Author: | md [ Sat Jan 03, 2009 3:23 am ] |
Post subject: | RE:A couple of questions about C? |
Dr.Scheme is also not C ![]() The "K&R book" is called "The C Programming Language", by Kernighan & Ritchie. ISBN 0-13-110362-8 (Second edition), Published by Prentice Hall. |
Author: | btiffin [ Sat Jan 03, 2009 9:34 am ] |
Post subject: | RE:A couple of questions about C? |
php11; This might sound a little harsh. Dig in, grit your teeth and figure out the command line. Developers need to know CLI's. Not knowing a command line interface (or two, or nine, or fifty) and using the crutch of a GUI is like trying to be a Writer without knowing the alphabet; really. And md is correct, DrScheme is a Lisp language derivative, not C. Dig in; get used to the command line and pick up a copy of Ch. Learn C by interacting with C. Then get gcc and sling code through a compiler. Persistence is not futile. Cheers |
Author: | php111 [ Sat Jan 03, 2009 10:42 am ] | ||
Post subject: | Re: A couple of questions about C? | ||
I tried to write hello, world I get an error. Here is a copy of my output.
|
Author: | Vertico [ Sat Jan 03, 2009 11:39 am ] |
Post subject: | Re: A couple of questions about C? |
Can you show the code you tried to compile |
Author: | php111 [ Sat Jan 03, 2009 12:02 pm ] |
Post subject: | Re: A couple of questions about C? |
Vertico @ Sat Jan 03, 2009 11:39 am wrote: Can you show the code you tried to compile
I just tried hello, world. I don't know how to compile via command line. I was reading the Ch docs up to the hello, world. I don't understand it. |
Author: | wtd [ Sat Jan 03, 2009 1:48 pm ] | ||
Post subject: | RE:A couple of questions about C? | ||
Compiling and running "Hello, world" is really quite simple. Assuming you have your code in a file called hello_world.c:
|
Author: | php111 [ Sat Jan 03, 2009 1:53 pm ] |
Post subject: | Re: A couple of questions about C? |
I still don't understand how to run it. It's not simple. If it was simple then why didn't it run for me? Why am I getting errors? It means it's not simple. I stated this more then enough times. I state again, command line is NOT for me. Period. I don't understand it. I posted the message I got. |
Author: | wtd [ Sat Jan 03, 2009 2:53 pm ] |
Post subject: | RE:A couple of questions about C? |
What errors are you getting? |
Author: | php111 [ Sat Jan 03, 2009 3:12 pm ] | ||
Post subject: | Re: A couple of questions about C? | ||
php111 @ Sat Jan 03, 2009 10:42 am wrote: I tried to write hello, world
I get an error. Here is a copy of my output.
That is the error in my quote. |
Author: | michaelp [ Sat Jan 03, 2009 3:19 pm ] |
Post subject: | RE:A couple of questions about C? |
You have to actually make a file with C code in it to run it. And it shouldn't have spaces in it either. (The name of the file and executable) |
Author: | Tony [ Sat Jan 03, 2009 4:24 pm ] | ||
Post subject: | RE:A couple of questions about C? | ||
just so that we are clear...
is not a valid C program. |
Author: | php111 [ Sat Jan 03, 2009 5:33 pm ] |
Post subject: | Re: A couple of questions about C? |
If no one won't help me find a C GUI then I won't learn. I am not going to keep trying command line. It's non sense. I will be more happy when I find a GUI. |
Author: | Vertico [ Sat Jan 03, 2009 5:41 pm ] |
Post subject: | Re: A couple of questions about C? |
It sounds like you tried not to run a program/code, but a random string you typed in "Hello, word". This isn't a C program nor a valid command just like the error told you. |
Author: | Tony [ Sat Jan 03, 2009 5:43 pm ] |
Post subject: | RE:A couple of questions about C? |
Then perhaps you would feel more comfortable with Visual Basic. Or even better, LEGO Mindstorm's GUI, where you drag blocks of code into flow-charts! No typing required ![]() Seriously though, if you have such an affinity for GUI, then C is likely a bad choice of a programming language for you to learn with. |
Author: | php111 [ Sat Jan 03, 2009 5:46 pm ] |
Post subject: | Re: RE:A couple of questions about C? |
Tony @ Sat Jan 03, 2009 5:43 pm wrote: Then perhaps you would feel more comfortable with Visual Basic. Or even better, LEGO Mindstorm's GUI, where you drag blocks of code into flow-charts! No typing required
![]() Seriously though, if you have such an affinity for GUI, then C is likely a bad choice of a programming language for you to learn with. I do want to try Ch but I don't understand how to compile using it. |
Author: | Tony [ Sat Jan 03, 2009 6:00 pm ] |
Post subject: | RE:A couple of questions about C? |
you don't, it's an interpreter. An interactive interpreter at that -- you just type in C statements, and get the result displayed as soon as there's a complete block to run. |
Author: | php111 [ Sat Jan 03, 2009 6:35 pm ] |
Post subject: | Re: RE:A couple of questions about C? |
Tony @ Sat Jan 03, 2009 6:00 pm wrote: you don't, it's an interpreter. An interactive interpreter at that -- you just type in C statements, and get the result displayed as soon as there's a complete block to run. [quote="Tony"]
Are you talking about Ch? I am on my mobile right now. |
Author: | michaelp [ Sat Jan 03, 2009 8:06 pm ] |
Post subject: | RE:A couple of questions about C? |
Yes, he is. |
Author: | ClayWall [ Sat Jan 03, 2009 9:11 pm ] |
Post subject: | RE:A couple of questions about C? |
You could try Bloodshed Dev C++ IDE (you will still need MinGW) it will compile C code, but like Tony said if you can't figure out command line I don't think you will get very far, as the majority of languages are command line driven in some way I believe. Correct me if I'm wrong. [Edit] - Forgot to give you some URL's http://sourceforge.net/project/showfiles.php?group_id=2435 - I'm assuming you are using Windows, though there are other versions. http://www.bloodshed.net/dev/devcpp.html * They are both free. |
Author: | md [ Sat Jan 03, 2009 10:28 pm ] |
Post subject: | Re: RE:A couple of questions about C? |
ClayWall @ 2009-01-03, 9:11 pm wrote: You could try Bloodshed Dev C++ IDE (you will still need MinGW) it will compile C code, but like Tony said if you can't figure out command line I don't think you will get very far, as the majority of languages are command line driven in some way I believe. Correct me if I'm wrong.
[Edit] - Forgot to give you some URL's http://sourceforge.net/project/showfiles.php?group_id=2435 - I'm assuming you are using Windows, though there are other versions. http://www.bloodshed.net/dev/devcpp.html * They are both free. Dev-C++ is a horrible IDE. So while it's something, I would strongly recommend against it. Since you don't like the command line I will assume you are using windows - in which case I strongly recommend Visual Studio. There is a free version that is more then adequate for learning and there is no better IDE for windows. Not wanting to learn the command line will ultimately doom you however. C is mostly taught through the command line, and almost any book/guide you are using to learn will involve writing command line programs, not GUI programs. |
Author: | OneOffDriveByPoster [ Sat Jan 03, 2009 10:34 pm ] |
Post subject: | Re: A couple of questions about C? |
I thought that Visual Studio did not come with a C compiler. |
Author: | md [ Sat Jan 03, 2009 11:21 pm ] |
Post subject: | Re: A couple of questions about C? |
OneOffDriveByPoster @ 2009-01-03, 10:34 pm wrote: I thought that Visual Studio did not come with a C compiler.
Yes and no, it's really targeted at managed languages and C++. However you can compile C code without too much issue (see http://www.daniweb.com/forums/thread16256.html for example). Likewise, while C++ is not a strict superset of C, well written C that does not take full advantage of all the features can usually be compiled without issue in a C++ compiler. |
Author: | btiffin [ Sun Jan 04, 2009 9:08 am ] | ||
Post subject: | Re: A couple of questions about C? | ||
php111; Try this; start up Ch, then at the "> " prompt type
After that, start here http://www.softintegration.com/docs/ch/gettingstart/ and work through the examples. As the first line of the page states Quote: Like mastering a natural language, it takes time to perfect one's skill in any programming language.
As you will see a little further down the gettingstart page, Ch also has a trial Student Edition. The student edition ships with a graphical ChIDE. Once you've played with the Ch interpreter for a bit, try the gui ChIDE, and then once you are a little more comfortable, get yourself an actual compiler. I'd suggest command line gcc, but Microsoft also ships zero-cost Visual Studio Express editions for the graphically inclined. Small warning; using "free" Microsoft development tools can make you a good Windows programmer. From that point forward you may become "locked in" to Microsoft. Nothing really wrong with that, as long as you go in with your eyes open. Vendor lock-in has good points and bad points. For me, the bad outweighs the good, but your mileage may vary. If you really want a fun graphical programming experience, maybe Scratch would be a good choice. http://scratch.mit.edu/ Scratch is built for learning and is a "drag and drop" environment. Derived from Smalltalk, once you've got the hang of Scratch all the other languages may start to make a lot more sense. Cheers Edit; typos and added a bit about Scratch. |
Author: | php111 [ Sun Jan 04, 2009 5:58 pm ] |
Post subject: | Re: A couple of questions about C? |
How does my commands look so far? Am I doing them right? |
Author: | wtd [ Sun Jan 04, 2009 10:29 pm ] | ||||||||
Post subject: | RE:A couple of questions about C? | ||||||||
Yes. Consider this line:
Now, for a full C program:
You can save that in hello_world.c and compile with:
Now you have an executable you can run.
|
Author: | btiffin [ Mon Jan 05, 2009 12:00 am ] | ||||||
Post subject: | Re: A couple of questions about C? | ||||||
php111; all right! getting there. ![]() Some more warnings; Ch is NOT C and there are some things in that tutorial that will NOT work under normal C programming.
works in Ch, but may kakk a C program. Without a semicolon a C compiler will give an error. With a semicolon
So ... as I think Ch is great for interactive learning of C, it isn't C and I'll warn you to be careful. You might want to get that 5th edition book you mentioned (find a cheap discount C programming book, there are lots, or go to the library) and type in the examples from the book. Ch will treat these full C programs as "scripts" that should run when you type in the filename (interpreted - not compiled, there is a very distinct difference). This may save you some confusion while coding C by avoiding inadvertently using some weird Ch enhancement that won't work in a C compiler. But welcome to command lines. Power at your fingertips. And the Ch command line is pretty powerful. ![]() With great power comes great responsibility. For instance; don't type
Cheers |
Author: | php111 [ Mon Jan 05, 2009 7:58 am ] |
Post subject: | Re: A couple of questions about C? |
1.) I am getting errors. I will give my screenshot. 2.) How do I save it in that file? 3.) I have my XP on H not C. I know I don't know DOS. I have MS-DOS 6.22 on drive C. |
Author: | btiffin [ Mon Jan 05, 2009 9:44 am ] | ||||
Post subject: | Re: A couple of questions about C? | ||||
php111; Yeah, Ch doesn't process #include lines while in interactive mode. Start up Ch and at the "> " prompt type pwd what comes back is the working directory. Use an editor to save hello.c to that afore mentioned working directory (in your case it will probably be H:/Documents and Settings/baseball) with this in the text file:
Then at the Ch "> " prompt type
Or ... use chparse and chrun, but skip that for now. The Ch installation has fairly good docs. The chguide.pdf Introduction chapter will help with this. Take some time, slow down a little maybe, spend 15 minutes or more going over the Introduction. Then crank up Ch and start at the top of the Introduction again. Learning programming will take some reading. This knowledge will not magically appear without some effort. And (don't feel bad about this part ... it's the rare individual that "gets" things on the first read without some previous experience), you may need to read the Introduction 5 times before you can leave the manual behind and start exploring on your own. Keep on plugging away php111. C and command lines and compilers and all the rest have a fairly steep initial learning curve. Before you know it though, lightbulbs come on and you won't even realize that you've learned new ways of thinking. Cheers |
Author: | php111 [ Mon Jan 05, 2009 2:08 pm ] |
Post subject: | Re: A couple of questions about C? |
btiffin, I am sorry. I am not really understanding how to save hello.c I know how to save a file. You pull up notepad, and save a file and give it a name. What lines am I putting in notpad to save? Should I leave the file type on default, which is .txt? I am not understanding. I don't have lines of code to save. Do you want me to type Hello World! in a notepad? Just like that Hello World! |
Author: | Vertico [ Mon Jan 05, 2009 2:47 pm ] |
Post subject: | Re: A couple of questions about C? |
As Btiffin said, open up notepad, type the code he gave you into it and save it. When you save the file, name it "hello.c", .c is the file extension you will be using instead of .txt |
Author: | php111 [ Mon Jan 05, 2009 4:09 pm ] |
Post subject: | Re: A couple of questions about C? |
I got the code right. It's just following the Ch docs I am getting errors. |
Author: | DemonWasp [ Mon Jan 05, 2009 4:37 pm ] |
Post subject: | RE:A couple of questions about C? |
You don't appear to have defined s, which is why printf ( s ) says that argument 1 is undefined or not a valid expression. You need to use all the lines for the little example there. First, do the: string_t s = "hello, world"; part, then you should be able to do: printf ( s ); |
Author: | php111 [ Mon Jan 05, 2009 4:58 pm ] |
Post subject: | Re: A couple of questions about C? |
Thank you. I did the string. How do I switch out of command mode in Ch? I did pwd. I can't use #include in command mode. Here is another screenshot. |
Author: | btiffin [ Tue Jan 06, 2009 3:41 am ] |
Post subject: | RE:A couple of questions about C? |
php111; Still plugging away, which is good. But now I fear by leading you to Ch I may have over complicated your life. ![]() There is no "switching out of command mode in Ch" persay, other than exiting. You exit Ch by typing exit at the "> " prompt. You need to step back and think about what's going on. Read the docs over (no typing ... just read, if you don't understand, just keep reading anyway). Learning C and other forms of programming is not a 5 minute affair. It can take days to get your head around things. I get a sense you want to keep trying, that's good, but this knowledge may not come without a fair amount of effort, patience and reading. Reading twice or three times sometimes. The name sounds a little derogatory, but it's a good book, written for learning. See if you can't find a copy of C for Dummies. It includes introductory material to help explain text files and editing and the different modes of thinking required when programming, along with the actual syntax of C. Cheers |
Author: | php111 [ Tue Jan 06, 2009 8:36 am ] |
Post subject: | Re: RE:A couple of questions about C? |
btiffin @ Tue Jan 06, 2009 3:41 am wrote: php111;
I get a sense you want to keep trying, that's good, but this knowledge may not come without a fair amount of effort, patience and reading. Reading twice or three times sometimes. You are right I do want to learn. I am slower then others to learn. I give up easy. I don't want to give up. I just don't understand how to run #include. I don't understand how to run it. I keep getting a command mode error. Someone at DevShed forrums said if I was to read C for Dummmied then I shouldn't be learning any language if I am reading a for Dummies book. |
Author: | DemonWasp [ Tue Jan 06, 2009 10:18 am ] |
Post subject: | RE:A couple of questions about C? |
#include, as with all lines that begin with # in C or C++, is a preprocessor directive. The preprocessor is the first thing that looks at a full C++ program, and it will do simple things like #includes and #defines and so on. Most of these are simple text-substitution (the preprocessor doesn't really need to understand your code). They are NOT commands, which is why you cannot access them in command mode. I'm not familiar with Ch, but I suspect it is smart enough to include a few basic utilities for you. You do not, in any case, seem to need to #include stdio.h, since you appear to have printf(), which is found in stdio.h. This is probably covered in your C for Dummies book. Don't be discouraged by others poo-pooing your efforts; learning to program is a challenge (and frankly, I wouldn't have recommended C as a first language, but that's another story), but it's a gratifying one. Books are, in any case, one of the best ways to start; I have no recommendations, but I'm sure someone here would be more than willing to suggest the next book you should take a look at. Don't stop reading if you don't understand something; keep going, or skip to the next chapter if you can, leaving a note to come back later. Programming often relies on some very strange concepts that are difficult to understand at first, but obvious once you "get it". |
Author: | php111 [ Tue Jan 06, 2009 10:42 am ] |
Post subject: | Re: A couple of questions about C? |
So, I don't need to use #include? I never heard of a complier couldn't use it before. I remember using Visual Studio by Microsoft. It was able to support #include. It took me a while to compile but it supported #include. When I say support, I mean if I was doing it right I didn't get any errors and it would compile. As that said, I am being more uncomfortable. I know my command are right. I am going to be expecting more, and more errors. |
Author: | DemonWasp [ Tue Jan 06, 2009 11:04 am ] |
Post subject: | RE:A couple of questions about C? |
The key difference here is that Ch is in an interpretive mode. It is NOT compiling your C++ code. You may not NEED to do the #include (though Wikipedia leads me to believe that there may be ways to include things, I'm hesitant to install Ch on my work machine to test that). There are almost certainly no C or C++ compilers that do not support #include; even those made in computer programming classes likely include the feature. It's one of the earliest parts of the language. The reason compiling takes so long is that the code file you're compiling may end up being on the order of a million lines long. That may seem confusing, given as your own code is only about 5 lines long, but that's ignoring what #include does. Each #include is like "copy and paste the specified file into this file", which means that your resulting code has all of stdio.h (and stdio.C) and whatever else you decide to include. Don't worry too much about getting errors. The most experienced programmers in the world constantly make errors (that's why we have programs to check for us!). Understanding how to fix the error is the tricky part, but it becomes easier with practice. |
Author: | php111 [ Tue Jan 06, 2009 11:12 am ] |
Post subject: | Re: A couple of questions about C? |
I have mutiple operations together. What does that mean? |
Author: | php111 [ Tue Jan 06, 2009 11:26 am ] | ||
Post subject: | Re: A couple of questions about C? | ||
Here is some C code that I want to work with. I believe I am doing the code wrong? Here is the code from the C Primer Plus, 5th edition book. Dan, recommended it in one of my earlier book threads.
Here is my screenshot with my code. |
Author: | DemonWasp [ Tue Jan 06, 2009 11:57 am ] |
Post subject: | RE:A couple of questions about C? |
Try it without the remains of the #include directive. That is, remove the < stdio.h > nonsense - that was part of the include. You don't need it. |
Author: | php111 [ Tue Jan 06, 2009 12:18 pm ] | ||
Post subject: | Re: RE:A couple of questions about C? | ||
DemonWasp @ Tue Jan 06, 2009 11:57 am wrote: Try it without the remains of the #include directive. That is, remove the < stdio.h > nonsense - that was part of the include. You don't need it.
I am missing characters in my code. I don't see where I am missing. I was comparing my code in Ch to the code in the book. I don't see a different. I see they are the same. Code from book:
|
Author: | wtd [ Tue Jan 06, 2009 12:38 pm ] |
Post subject: | RE:A couple of questions about C? |
I don't see a final }. |
Author: | php111 [ Tue Jan 06, 2009 12:49 pm ] |
Post subject: | Re: RE:A couple of questions about C? |
wtd @ Tue Jan 06, 2009 12:38 pm wrote: I don't see a final }.
If you don't see a final. Why is it failing to compile my code as shown above? |
Author: | Vertico [ Tue Jan 06, 2009 3:18 pm ] |
Post subject: | Re: RE:A couple of questions about C? |
php111 @ Tue Jan 06, 2009 1:49 pm wrote: wtd @ Tue Jan 06, 2009 12:38 pm wrote: I don't see a final }.
If you don't see a final. Why is it failing to compile my code as shown above? If you look at the error, then reread wtd's post, it would make more scene. { return 0; } |
Author: | php111 [ Tue Jan 06, 2009 3:33 pm ] |
Post subject: | Re: A couple of questions about C? |
I got the final }. I get more errors. It's never working for me. |
Author: | php111 [ Tue Jan 06, 2009 3:42 pm ] |
Post subject: | Re: A couple of questions about C? |
How do I change my syntax file from include to printf? I almost have it. |
Author: | Vertico [ Tue Jan 06, 2009 3:49 pm ] |
Post subject: | Re: A couple of questions about C? |
Re-write the code out in notepad or something, give it correct spacing and indentation. Trying to look through that is hurting my eyes and it will make it much easier for you to find your mistakes. Might I also suggest getting away from Ch and use some more native like C? |
Author: | php111 [ Tue Jan 06, 2009 4:11 pm ] |
Post subject: | Re: A couple of questions about C? |
Vertico @ Tue Jan 06, 2009 3:49 pm wrote: Re-write the code out in notepad or something, give it correct spacing and indentation.
Trying to look through that is hurting my eyes and it will make it much easier for you to find your mistakes. Might I also suggest getting away from Ch and use some more native like C? It's hurting mine as well. I'll be 27 in a few weeks. I have bad eyes since birth. I wear glasses. What do you mean by native C? Don't learn C, and go with something else? I really want to learn C but not with Ch. It was recommended to me. |
Author: | php111 [ Tue Jan 06, 2009 5:09 pm ] | ||
Post subject: | Re: A couple of questions about C? | ||
I tried it in notepad. I am still getting errors. I am just learning. I will post the errors first in a qoute. I will then post my code in code tags. Quote: H:/Documents and Settings/baseball> ./cprogramming.c
ERROR: missing ')' ERROR: syntax error before or at line 7 in file H:\DOCUME~1\baseball\CPROGR~1.C ==>: printf("printf("My favorite number is %d because it is first.\n",num); BUG: printf("printf("My<== ??? ERROR: missing " ERROR: cannot execute command 'H:\DOCUME~1\baseball\CPROGR~1.C' H:/Documents and Settings/baseball>
|
Author: | Vertico [ Tue Jan 06, 2009 5:31 pm ] | ||
Post subject: | Re: A couple of questions about C? | ||
php111 @ Tue Jan 06, 2009 6:09 pm wrote: printf("printf("My favorite number is %d because it is first.\n",num); [/code] You have written printf twice. You also missed the end }
[/code] Ch is some sort of rework of the C language. I know nothing about it other then what I have seen in this thread, but it seems to be some sort of learning tool? I am suggesting you use/write C in the traditional scene. Open an IDE/Editor (like notepad) type all your code in there, save it with the extension .c (ex. helloWorld.c ) then compile and run the code through either the IDE or command prompt. |
Author: | php111 [ Tue Jan 06, 2009 5:54 pm ] |
Post subject: | Re: A couple of questions about C? |
I done it!!!!! I used ./the name of my file.c in Ch. I wrote the code using notepad. That was easier then using Ch to write it. Should I keep writing the same code, or move on? If I write it again then I just delete that code. Thank you everyone who replied. I wait to see to rewrite or continue. |
Author: | Vertico [ Tue Jan 06, 2009 7:17 pm ] |
Post subject: | Re: A couple of questions about C? |
Congratulations! Your best bet would be to continue to build off what you know. Perhaps try some arithmetic (add / subtract / divide / multiple your variables) Learn how to use scanf() (Read formatted data) The more and more you learn, the easier these last few steps will seem to you. |
Author: | php111 [ Tue Jan 06, 2009 7:29 pm ] |
Post subject: | Re: A couple of questions about C? |
Vertico @ Tue Jan 06, 2009 7:17 pm wrote: Congratulations!
Your best bet would be to continue to build off what you know. Perhaps try some arithmetic (add / subtract / divide / multiple your variables) Learn how to use scanf() (Read formatted data) The more and more you learn, the easier these last few steps will seem to you. Do I do that with that printf code above? If so, how do I do that? |
Author: | Vertico [ Tue Jan 06, 2009 7:48 pm ] | ||||
Post subject: | Re: A couple of questions about C? | ||||
Quick examples:
|
Author: | php111 [ Tue Jan 06, 2009 8:35 pm ] | ||
Post subject: | Re: A couple of questions about C? | ||
I got a whole list of errors with your first code. My errors: Quote: H:/Documents and Settings/baseball> test1.c
ERROR: maybe missing ';' ERROR: syntax error before or at line 3 in file test1.c ==>: int firstNumber = 3 secondNumber = 2 thirdNumber = 0; BUG: int<== ??? ERROR: variable 'thirdNumber' not defined ERROR: command 'thirdNumber' not found ERROR: syntax error before or at line 7 in file test1.c ==>: thirdNumber = firstNumber + secondNumber BUG: thirdNumber = firstNumber + secondNumber<== ??? ERROR: variable 'thirdNumber' not defined ERROR: command 'thirdNumber' not found ERROR: syntax error before or at line 11 in file test1.c ==>: thirdNumber = firstNumber - secondNumber; BUG: thirdNumber = firstNumber - secondNumber;<== ??? ERROR: cannot execute command 'test1.c' H:/Documents and Settings/baseball> My code:
|
Author: | Vertico [ Tue Jan 06, 2009 8:41 pm ] | ||
Post subject: | Re: A couple of questions about C? | ||
If you look at your code compared to what I posted, there are a few differences. First off, the line in which the three variables are declared needs to be separated. theres a little , between them if you look closely.
Because you took out the , the compiler doesn't recognize that three different variables are being declared, and you get an error. You also removed the return 0; at the end which is needed to tell the program that the code has been executed successfully. As well, you need to leave the opening and closing brackets { } around the code so that the compiler knows where main starts and ends. Take another look at what I posted. |
Author: | php111 [ Tue Jan 06, 2009 9:01 pm ] | ||
Post subject: | Re: A couple of questions about C? | ||
I fixed it and still get errors.
Quote: H:/Documents and Settings/baseball> test1.c
ERROR: multiple operands together ERROR: syntax error before or at line 12 in file test1.c ==>: printf("%d plus %d \n", firstNumber, secondNumber, thirdNumber); BUG: printf("%d plus %d \n", firstNumber, secondNumber, thirdNumber)<== ??? ERROR: cannot execute command 'test1.c' H:/Documents and Settings/baseball> |
Author: | OneOffDriveByPoster [ Tue Jan 06, 2009 10:01 pm ] |
Post subject: | Re: A couple of questions about C? |
php111 @ Tue Jan 06, 2009 9:01 pm wrote: Quote: H:/Documents and Settings/baseball> test1.c
ERROR: multiple operands together ERROR: syntax error before or at line 12 in file test1.c ==>: printf("%d plus %d \n", firstNumber, secondNumber, thirdNumber); BUG: printf("%d plus %d \n", firstNumber, secondNumber, thirdNumber)<== ??? ERROR: cannot execute command 'test1.c' H:/Documents and Settings/baseball> |
Author: | Vertico [ Tue Jan 06, 2009 10:14 pm ] | ||||
Post subject: | Re: A couple of questions about C? | ||||
php111 @ Tue Jan 06, 2009 10:01 pm wrote: I fixed it and still get errors.
Quote: H:/Documents and Settings/baseball> test1.c
ERROR: multiple operands together ERROR: syntax error before or at line 12 in file test1.c ==>: printf("%d plus %d \n", firstNumber, secondNumber, thirdNumber); BUG: printf("%d plus %d \n", firstNumber, secondNumber, thirdNumber)<== ??? ERROR: cannot execute command 'test1.c' H:/Documents and Settings/baseball> The thing with programming is you need to understand your errors. When the screen screams ERROR at you, it usually has a reference to the problem. If you ever want to get far at this, you need to start looking at the errors you are getting and truly examine them. At this stage, they are very easy to understand and typically point to the correct point in the code. Your error points you straight to the actual line with the error on it. Can you see the difference between what you typed, and what I typed?
|
Author: | php111 [ Wed Jan 07, 2009 10:09 am ] | ||
Post subject: | Re: A couple of questions about C? | ||
I have been looking at your line. I put the equals in and still get errors. I see the line that the command tells me. Quote: ERROR: multiple operands together
ERROR: syntax error before or at line 12 in file H:\DOCUME~1\baseball\test1.c ==>: printf("%d plus %d equals %d. \n", firstNumber, secondNumber, thirdNumber ); BUG: printf("%d plus %d equals %d. \n", firstNumber, secondNumber, thirdNumber )<== ??? ERROR: cannot execute command 'H:\DOCUME~1\baseball\test1.c' H:/Documents and Settings/baseball>
|
Author: | DemonWasp [ Wed Jan 07, 2009 11:03 am ] |
Post subject: | RE:A couple of questions about C? |
You're missing a semicolon on the end of the line immediately after "printf ( "This is a test file \n" );". Since that line lacks a closing semicolon, it figures that the next line is a continuation of the statement, and gets confused when it doesn't make any sense. That's why it's giving the syntax error there. |
Author: | php111 [ Wed Jan 07, 2009 11:27 am ] |
Post subject: | Re: RE:A couple of questions about C? |
DemonWasp @ Wed Jan 07, 2009 11:03 am wrote: You're missing a semicolon on the end of the line immediately after "printf ( "This is a test file \n" );".
Since that line lacks a closing semicolon, it figures that the next line is a continuation of the statement, and gets confused when it doesn't make any sense. That's why it's giving the syntax error there. What? I have the semicolon. What do you mean? printf("This is a test file \n"); |
Author: | wtd [ Wed Jan 07, 2009 11:35 am ] |
Post subject: | RE:A couple of questions about C? |
The line after that one. |
Author: | DemonWasp [ Wed Jan 07, 2009 11:47 am ] |
Post subject: | RE:A couple of questions about C? |
What wtd said. This is a vital skill to any programmer, so pay attention: you need to look at EXACTLY what you've given the computer, not what you *think* you've given it. The two may be different in an incredibly subtle way (missing semicolon, less-than instead of less-than-or-equal-to, etc), but it could be the source of a huge problem. When you encounter a problem like this, start reading the code exactly like the computer would. Start with the first line, and make sure it does exactly what you think it does. It's slow and tedious at first, but once you get the hang of it, it becomes much easier. |
Author: | php111 [ Wed Jan 07, 2009 12:04 pm ] | ||
Post subject: | Re: A couple of questions about C? | ||
I finally got the first code right. The second code.
Do I write exactly this one line, You entered in %d? |
Author: | php111 [ Wed Jan 07, 2009 1:43 pm ] |
Post subject: | Re: A couple of questions about C? |
I done it. 13 I gave the number 13. I am going to make a new thread for the errors I get with the book. Thank you everyone. |
Author: | jain.rani [ Mon Jul 13, 2009 10:42 pm ] |
Post subject: | Re: A couple of questions about C? |
//this is simple c program for hello word. #include<stdio.h> int main(){ printf("Hello, word"); return 0; } Thanks |