Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 A couple of questions about C?
Index -> Programming, C -> C Help
Goto page Previous  1, 2, 3, 4, 5  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
php111




PostPosted: 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.



Clipboard02.jpg
 Description:
 Filesize:  122.43 KB
 Viewed:  133 Time(s)

Clipboard02.jpg


Sponsor
Sponsor
Sponsor
sponsor
btiffin




PostPosted: 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:
code:

#include <stdio.h>

int main() {
    printf("hello, world");
    return 0;
}

Then at the Ch "> " prompt type
code:
./hello.c
and you should see the output.

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
php111




PostPosted: 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!
Vertico




PostPosted: 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
php111




PostPosted: 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.


Clipboard03.jpg
 Description:
 Filesize:  150.23 KB
 Viewed:  136 Time(s)

Clipboard03.jpg


DemonWasp




PostPosted: 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 );
php111




PostPosted: 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.


Clipboard04.jpg
 Description:
 Filesize:  102.52 KB
 Viewed:  117 Time(s)

Clipboard04.jpg


btiffin




PostPosted: 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. Sad

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
Sponsor
Sponsor
Sponsor
sponsor
php111




PostPosted: 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.
DemonWasp




PostPosted: 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".
php111




PostPosted: 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.
DemonWasp




PostPosted: 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.
php111




PostPosted: 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?


Clipboard01.jpg
 Description:
 Filesize:  113.32 KB
 Viewed:  108 Time(s)

Clipboard01.jpg


php111




PostPosted: 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.




code:
#include <stdio.h>

int main(void) /* a simple program */

{

int num; /* define a variable called num */

num = 1; /* assign a value to num */



printf("I am a simple "); /* use the printf() function */

printf("computer.\n");

printf("My favorite number is %d because it is first.\n",num);



return 0;





Here is my screenshot with my code.



Clipboard02.jpg
 Description:
 Filesize:  177.61 KB
 Viewed:  138 Time(s)

Clipboard02.jpg


DemonWasp




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, C -> C Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 3 of 5  [ 72 Posts ]
Goto page Previous  1, 2, 3, 4, 5  Next
Jump to:   


Style:  
Search: