LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   New C programmer (https://www.linuxquestions.org/questions/programming-9/new-c-programmer-805708/)

abakhiet 05-03-2010 04:27 PM

New C programmer
 
Hola,
i'm a new to c programming under linux, but i make a lot of scripts using Bash scripting, and i was put in Bash header this line :
Code:

#!/bin/bash
where it is the location of bash language, so when i wrote a C program, what is the required packages and what is my header :D
i'm using :
Code:

Linux Centos 5.4
Thanks in advance :D

acid_kewpie 05-03-2010 04:29 PM

erm... what?? :confused: Are you looking for an equivalent line for c coding? There isn't one, as C is compiled code, not a script. Whatever you do mean, telling us you're using CentOS is not going to help a bit, I'm sure.

JohnGraham 05-03-2010 04:44 PM

Like acid_kewpie said, C is a compiled language, so there's nothing akin to the '#!/bin/bash' line for C.

Maybe you should go through chapter 2 of this to give yourself an introduction to a compiled language, and then get an introductory C book (like K&R or Teach Yourself C in 21 Days) to actually learn C itself.

Sergei Steshenko 05-03-2010 04:50 PM

Well, there are "C" interpreters: http://en.wikipedia.org/wiki/Ch_interpreter -> http://root.cern.ch/drupal/content/cint , etc.

alan99 05-03-2010 10:19 PM

bash is simply a shell to run system commands. (similar to a DOS or window batch file)

ArthurSittler 05-04-2010 04:11 AM

I recommend The C Programming Language second edition, by Brian W. Kernighan and Dennis M. Ritchie, ISBN 0-13-110163-3. My first impression (of the first edition) was that it was terse. Now I think of it as concise, but complete. It is the definition of the language and the authoritative reference.
Since you have been using shell scripts, you are familiar with editing text files and running commands at a console prompt.
I don't mean to minimize the issues in getting started. It is indeed a major hurdle to get the hello world program running.
There are other issues as well. Notably, many or most new C programmers take a while to become comfortable with pointers. And, in C, there is an intimate relation between pointers and handling arrays.
Another important concept is the structure, which groups related data of different types together.
Dynamic allocation of storage at run time is yet another important feature of C. A very common application involves allocating structures containing pointers to their own structure type as well as containing other data or pointers to other data, and connecting these together into "linked lists" of data.
All these issues, and others are explained in the cited book.
Finally, it is easier to learn C (and many other things) along with other people similarly interested. This is one of the major advantages of a school environment, but you can go it alone or associate with other similarly interested people on the internet. There are also some of us on the internet who are willing to help you with learning the C language and many other aspects of programming and other fields of inquiry as well.

Sergei Steshenko 05-04-2010 09:38 AM

Modern C99 is quite (?) different from the original K&R "C".

orgcandman 05-04-2010 12:16 PM

Quote:

Originally Posted by Sergei Steshenko (Post 3956906)
Modern C99 is quite (?) different from the original K&R "C".

K&R C 2nd ed. covers c89/c90 (they're almost identical with a few caveats about implicit return typing). While it is quite a bit different from the original 1970s version of C, for the most part it covers most of the important things. c89/90 added a lot of enhancements from C++ (for instance, function pointers, and the ability to return non-base datatypes like structs/unions).

c99 includes inlines, // comments in addition to /**/ comments, some additional data types (including variadics), and variable length arrays. There are probably some additional enhancements, but for the most part if you wrote something adherent to c89/c90 it will compile with few, if any, warnings.

All I'm saying is, while there are plenty of nice additions, carefully written k&r C is still legal C code today.

@OP:
If you're not comfortable with jumping into compiling/linking/etc. right away, and want really fast results on things like hello world and simple things, check out tcc (http://bellard.org/tcc/) as it includes the ability to interpret C code and execute it "on-the-fly." Put that in perls pipe and smoke it!


All times are GMT -5. The time now is 02:34 AM.