Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
first line of C programs...
View unanswered posts
View posts from last 24 hours

Goto page 1, 2, 3  Next  
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Gnufsh
Guru
Guru


Joined: 28 Dec 2002
Posts: 400
Location: Portland, OR

PostPosted: Sat Jan 25, 2003 4:36 am    Post subject: first line of C programs... Reply with quote

Hi. I just started a CS class this week where we are learning C. I figured I'd catch up on some work with my gentoo box. The lab we've been learning on runs redhat 7.3. Our first line has always been

#include <begin.h>

well, when I try to compile on my gentoo box, I get an error about not being able to find this. So I did a search and it doesn't exist. What do I need to include instead to make simple programs work (we're talking hello world stuff here)?

Thanks,

-Dan
Back to top
View user's profile Send private message
shm
Advocate
Advocate


Joined: 09 Dec 2002
Posts: 2380
Location: Atlanta, Universe

PostPosted: Sat Jan 25, 2003 5:00 am    Post subject: Reply with quote

I've never heard of a begin.h in the C stdlib. Perhaps it was a header file included in the project? Or perhaps it's a header file that is specific to the class that is installed on the rh machines.
Back to top
View user's profile Send private message
aja
l33t
l33t


Joined: 26 Aug 2002
Posts: 705
Location: Edmonton, Canada

PostPosted: Sat Jan 25, 2003 5:04 am    Post subject: Reply with quote

I've never heard of <begin.h>. I'm guessing that it is a header that your school uses to wrap some functions that it considers standard for any of the lab programs. As such, it would be installed on your lab computers (judging by the syntax, in your default library location) -> you could probably just copy it and take it home.

If you post the code to your program, I or others could probably tell you what headers it would be looking for. At a guess, try including <iostream.h> and/or <stdio.h> and <stdlib.h>
Back to top
View user's profile Send private message
carmiac
n00b
n00b


Joined: 25 Aug 2002
Posts: 46

PostPosted: Sat Jan 25, 2003 5:09 am    Post subject: Reply with quote

I have never heard of <begin.h>, Im wondering if that is a custom .h file (that was put in the system header file directory) that your lab is using.

Anyway, for the most basic app you will want to #include <stdio.h> so you get access to printf and such. Other common headers to include (for me at least, I do instrument programming) are math.h and time.h.

Have Fun!
_________________
A watched emerge never compiles.
Back to top
View user's profile Send private message
Gnufsh
Guru
Guru


Joined: 28 Dec 2002
Posts: 400
Location: Portland, OR

PostPosted: Sat Jan 25, 2003 5:50 pm    Post subject: Reply with quote

thanks alot for the quick replys. I'll tell ya' how it goes.
Back to top
View user's profile Send private message
Gnufsh
Guru
Guru


Joined: 28 Dec 2002
Posts: 400
Location: Portland, OR

PostPosted: Sat Jan 25, 2003 5:56 pm    Post subject: Reply with quote

For this first project, we're usinf functions like outputstring() and outputdouble(), along with basic math functions. What do I need for those?
Back to top
View user's profile Send private message
rac
Bodhisattva
Bodhisattva


Joined: 30 May 2002
Posts: 6553
Location: Japanifornia

PostPosted: Sat Jan 25, 2003 6:05 pm    Post subject: Reply with quote

Never heard of outputstring or outputdouble, so those are probably convenience macros included in the magical begin.h. You could probably implement them with printf.
_________________
For every higher wall, there is a taller ladder
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20067

PostPosted: Sat Jan 25, 2003 6:07 pm    Post subject: Reply with quote

Is begin.h perhaps something the school/professor is supplying? Maybe you can get permission to take a copy home, along with other similar local settings.
_________________
Quis separabit? Quo animo?
Back to top
View user's profile Send private message
carmiac
n00b
n00b


Joined: 25 Aug 2002
Posts: 46

PostPosted: Sat Jan 25, 2003 6:27 pm    Post subject: Reply with quote

Wow, sounds like your school is trying really hard to wrap everything messy in C into something else. This could really hurt you in the end since they are effectively not teaching you real C, but rather their own "prettified" version of it. You might want to ask your prof why they are doing this.

Anyway, I would be interested in seeing this begin.h file if you get ahold of it.
_________________
A watched emerge never compiles.
Back to top
View user's profile Send private message
rac
Bodhisattva
Bodhisattva


Joined: 30 May 2002
Posts: 6553
Location: Japanifornia

PostPosted: Sat Jan 25, 2003 6:36 pm    Post subject: Reply with quote

I agree with camiac: I once worked with a guy who used to use the C preprocessor to make things look like shell and/or Pascal: defining if/fi and begin/end to be {} and other such things.

Gnufsh, this might get you started until you can get your hands on begin.h:
Code:
#define outputstring(s) printf("%s\n",s)
#define outputdouble(d) printf("%f\n",d)

_________________
For every higher wall, there is a taller ladder
Back to top
View user's profile Send private message
int1
Tux's lil' helper
Tux's lil' helper


Joined: 08 Nov 2002
Posts: 139

PostPosted: Sat Jan 25, 2003 6:45 pm    Post subject: Reply with quote

gnufsh:

On one of the lab machines, do "ls -l /usr/include/begin.h". Assuming it is there, or if it is a link to the real file, you can grab it off the system and put it on yours.

I am in agreement with the others, however, that this may not be the best teaching approach. One of the first things I ever teach with C programming are the input and output functions, and their formats.

It might be entertaining for us to see this file also, so if you want to post it, we would be :lol:

int1
Back to top
View user's profile Send private message
aja
l33t
l33t


Joined: 26 Aug 2002
Posts: 705
Location: Edmonton, Canada

PostPosted: Sun Jan 26, 2003 6:32 am    Post subject: Reply with quote

<rant intensity=high>
Judging by the names of the functions you gave, your instructor might be emulating something called JJ -which is an online instructional system for java. One of the particularly broken pedagogical philosophies it seems to demonstrate is the idea that i/o in C, C+ and Java is 'too difficult' for beginning CS students. Consequently, they wrap the i/o in "easier" functions.

Speaking as a post-secondary instructor of computer programming (how's THAT for argumentum ad verecundiam?!), that idea is crap. It's analogous to teaching someone how to drive a standard transmission by training them in an automatic one.

My experience with instructors who say "that's too difficult for them to learn" is that they are really thinking "that's too difficult for me to teach". You shouldn't stand for it. If you are paying money to be trained in C programming, insist that you be trained in C. Admittedly, at first, you might have to use some I/O calls that you don't entirely understand, but at least they'll be the same calls you'll be making when you do understand it.

</rant>
Back to top
View user's profile Send private message
Gnufsh
Guru
Guru


Joined: 28 Dec 2002
Posts: 400
Location: Portland, OR

PostPosted: Sun Jan 26, 2003 10:41 am    Post subject: Reply with quote

Yeah, this is getting annoying. begin.h is located in a subdirectory of /GRDB. There are also some docs and other header files. Anyone heard of GRDB? I looked at begin.h, it includes a couple of standard files, and contains some function prototypes (but as far as I can tell, no actual functions). I'm not too happy with this class right now. I'm going to talk to my prof monday morning and see what he has to say about it.

Thanks so much for the help.
Back to top
View user's profile Send private message
OdinsDream
Veteran
Veteran


Joined: 01 Jun 2002
Posts: 1057

PostPosted: Sun Jan 26, 2003 3:54 pm    Post subject: Reply with quote

I suggest you take a careful look at the begin.h file, and figure out a way to break your professor's "outputstring()" macro, or function, or whatever it is. This would be the easiest way to demonstrate to him/her that this teaching method is flawed, and irrational. Could you post the contents of this file?
Back to top
View user's profile Send private message
uglyman
Apprentice
Apprentice


Joined: 21 Apr 2002
Posts: 216
Location: Seattle, WA USA

PostPosted: Tue Jan 28, 2003 4:56 am    Post subject: YEAH Reply with quote

I would also love to see it.

I am back in school now after a couple of years off and I am curious because I just retook the first C class and now I am taking the second.

What bugs me is that they don't even give you a full quarter of C anymore and that isn't enough to be able to work with old code like we deal with daily on our gentoo boxen. Now they move you right into C++ at which point they explain to you that java is the future and you should really be in that class.

later
ug
Back to top
View user's profile Send private message
Zadeh
Tux's lil' helper
Tux's lil' helper


Joined: 31 Oct 2002
Posts: 131

PostPosted: Wed Jan 29, 2003 1:33 pm    Post subject: Re: YEAH Reply with quote

uglyman wrote:

Now they move you right into C++ at which point they explain to you that java is the future and you should really be in that class.

I wonder if their Java instructors will soon tell them they should be in the C# class. :)
Back to top
View user's profile Send private message
Zadeh
Tux's lil' helper
Tux's lil' helper


Joined: 31 Oct 2002
Posts: 131

PostPosted: Wed Jan 29, 2003 1:40 pm    Post subject: Reply with quote

aja wrote:

If you post the code to your program, I or others could probably tell you what headers it would be looking for. At a guess, try including <iostream.h> and/or <stdio.h> and <stdlib.h>

Minor nit: new code shouldn't use <iostream.h> as it's a platform dependent, pre-standard C++ header (so it may not work at all in a C compiler).

Gnufsh: Does the course require a text? If so, what one? (Am curious)
Back to top
View user's profile Send private message
BigRedDot
n00b
n00b


Joined: 29 Oct 2002
Posts: 67
Location: Austin

PostPosted: Wed Jan 29, 2003 2:12 pm    Post subject: Reply with quote

Quote:
Now they move you right into C++ at which point they explain to you that java is the future and you should really be in that class.


I think you are generalizing a bit much. Maybe the place you are at is like this. Some places (MIT and Berkeley come to mind) start off students with scheme and the SICP book. Also, C is not a "stepping stone" language for C++. They are different languages, and when used well, idiomatic code in one bears only superficial resemblance to the other. However, both make awful "introduction to computing" languages, IMHO.
_________________
Even if you are one-in-a-million, there are still 6000 people just like you.
Back to top
View user's profile Send private message
Zadeh
Tux's lil' helper
Tux's lil' helper


Joined: 31 Oct 2002
Posts: 131

PostPosted: Wed Jan 29, 2003 2:28 pm    Post subject: Reply with quote

BigRedDot wrote:
...
Some places (MIT and Berkeley come to mind) start off students with scheme and the SICP book. Also, C is not a "stepping stone" language for C++. They are different languages, and when used well, idiomatic code in one bears only superficial resemblance to the other. However, both make awful "introduction to computing" languages, IMHO.


Harvard uses LISP and then C++. Not a bad choice either imo. When I started FORTRAN was a requirement for math majors. I think thats far worse punishment. :) (They still teach COBOL here too, can you believe it?)
Back to top
View user's profile Send private message
BigRedDot
n00b
n00b


Joined: 29 Oct 2002
Posts: 67
Location: Austin

PostPosted: Wed Jan 29, 2003 4:15 pm    Post subject: Reply with quote

Quote:
Harvard uses LISP and then C++. Not a bad choice either imo.

I agree that LISP or Scheme is a good start. First, because they can be used interactively, so that students can see the results of their experiments immediately. But mostly because the syntax is trivial: there is only one basic syntactic rule to know (and only one brace matching rule for an editor to follow). This means that you can concentrate on the abstract computing concepts (recursion, iteration, mapping operations over data) that are immediately applicable to any problem and any programming language without getting mired down in a forest of details specific to a particular case. Unfortunately, when you start with something like C, it's easy to lose sight of the fundamental concepts, and start thinking that the peculiars of pointers, compiling, linking, where you put a semicolon, etc. actually have anything at all to do with solving problems, which of course, they don't.
Quote:
When I started FORTRAN was a requirement for math majors. I think thats far worse punishment. :)

Interesting. As far as I know, all numerical computing classes in Physics and Mathematics at UT are taught in C. Although, the other day the professor in the graduate Classical Dynamics class I am sitting in on passed around some NAG and BLAS FORTRAN manuals for our edification. I am reminded of the aphorism: "I don't have any idea what the high-performance computing languge of fifty years from now will look like -- but I know it will be called FORTRAN"
Quote:
They still teach COBOL here too, can you believe it?

Not outside the the MIS or Business school, I hope!
_________________
Even if you are one-in-a-million, there are still 6000 people just like you.
Back to top
View user's profile Send private message
Zadeh
Tux's lil' helper
Tux's lil' helper


Joined: 31 Oct 2002
Posts: 131

PostPosted: Wed Jan 29, 2003 7:50 pm    Post subject: Reply with quote

Quote:

...
Unfortunately, when you start with something like C, it's easy to lose sight of the fundamental concepts, ...

s/easy/easier

Yeah I agree with the Scheme/Lisp advantages. I will resist the urge to say much more though as to not detract from the original topic. :)

Quote:

Not outside the the MIS or Business school, I hope!

Unfortunately, it is also a CS course. Not required though thank god, but some people actually take it on the advice of some really old-time recruiters from banks and insurance companies who still use it. (Just when you thought they might have to die off and 'switch' to something else, along comes COBOL.NET :))
Back to top
View user's profile Send private message
Gnufsh
Guru
Guru


Joined: 28 Dec 2002
Posts: 400
Location: Portland, OR

PostPosted: Wed Jan 29, 2003 7:53 pm    Post subject: Reply with quote

No text is required. I've started using printf instead of the "baby C" function-thingys. Here is begin.h (/GRDB/NG/begin.h):



#ifndef BeginDEF
#define BeginDEF

#include <beginnergraph.h>



#define or ||
#define and &&

#define maxstringlength 64

typedef char string [maxstringlength] ;

void inputdouble(double *px) ;
void inputstring(char *px) ;

void outputdouble(double x) ;
void outputstring(char *x) ;

double integerpart(double x) ;
double fractionalpart(double x) ;

double quotient(double a, double b) ;
double remainder(double a, double b) ;

double randomwhole() ;
/* random whole number >= 0, < several billion */

#endif

and here is the srcipt he has us run to compile (/GRDB/gcom):

#!/bin/csh

# may have to change GRDB to reflect where you installed all of this

sed -f /GRDB/NG/sed.control < $argv[1] > drawM.345.c
cc -I/GRDB/NG /GRDB/C/*.o drawM.345.c -L/usr/X11R6/lib -lm -lX11 -lXext
\rm drawM.345.*


what does it mean?
Back to top
View user's profile Send private message
Kumba
Developer
Developer


Joined: 16 Jul 2002
Posts: 393
Location: Sigma 957

PostPosted: Wed Jan 29, 2003 8:17 pm    Post subject: Reply with quote

Boy, if this is what your school does to "simplify" C, I'd hate to see how they "simplify" something like say, Visual Basic :P

That said, I agree with everyone else here. You should learn the standard C functions, not these pre-defined things. Maybe when you actually come to a full understanding of C and it's power (which I haven't even done yet), then for your own little side projects, you could #define things to make them easier to program in, but for learning, you should be learning raw C.

Sample below is your generic "Hello World!" C file. It's quick, simple, and basically gives you the basic structure of any C program.

Code:
// Our Header File, stands for "Standard Input/Output".
// This file prototypes alot of the common C functions, like printf().
#include <stdio.h>

// The "main" function.  EVERY C program has one of these.
int main(void) {
  // printf() is the print function.  This is it's most basic usage.  Usually
  // it can take a string containing formatting indicators, and then a set
  // of variables to display things like integers, floats, strings, and so on.
  // In this case, we're just going to print a string followed by a newline
  // character (the \n).
  printf("Hello World!\n");

  // Return the value of the function.  Good to always return a value
  // function types except "void" functions (which have no types).
  return 0;
}


To Compile in Linux ('$' is the prompt):
Code:
$> gcc hello.c -o hello
$> ./hello
Hello World!
$>


That is by far, the most generic example of C that I can think of, including comments. My style of C coding doesn't follow the more accepted styles (like placement of braces and such, spacing, etc..), but it gets the point across. As you learn, you'll adapt to your own coding style that should be within the ballpark of the "standard" version.

In the meanwhile, I'd complain to the instructor and/or those above him that you're not being taught proper C. Even if C at first proves to be a bit difficult, it pays off in the end because the knowledge you learn is adaptable in many situations. This "kiddified" version they are trying to teach will probably affect your ability to code C properly, because you will be used to the functions they teach you in this course that aren't a part of the ANSI C standard.


--Kumba
_________________
"The past tempts us, the present confuses us, the future frightens us. And our lives slip away, moment by moment, lost in that vast, terrible in-between."
--Emperor Turhan, Centauri Republic
Back to top
View user's profile Send private message
aja
l33t
l33t


Joined: 26 Aug 2002
Posts: 705
Location: Edmonton, Canada

PostPosted: Wed Jan 29, 2003 8:27 pm    Post subject: Reply with quote

Gnufsh wrote:

#define or ||
#define and &&


Oh....dear.....god. That's....that's....just awful. It's so majestic in its awfulness that it's almost .... beautiful.
Back to top
View user's profile Send private message
BigRedDot
n00b
n00b


Joined: 29 Oct 2002
Posts: 67
Location: Austin

PostPosted: Wed Jan 29, 2003 9:20 pm    Post subject: Reply with quote

Quote:
Gnufsh wrote:

#define or ||
#define and &&


Oh....dear.....god. That's....that's....just awful. It's so majestic in its awfulness that it's almost .... beautiful.


While not standard C, "and" and "or" (and some others) are standard C++, which seems to surprise many people.
_________________
Even if you are one-in-a-million, there are still 6000 people just like you.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum