Need help starting with C programming.... - Page 1
Forum section: electronics / beginners

author: doctorm
author_rank: Regular Contributor
timestamp: December 14, 2011, 06:32:25 am
content: hi guys,im not sure if this falls totally under electronics but i need help finding something to start me off with leanring C programming (not the C++ or anything; the basic C)?i just need a book, website, or something to help me learn the basics. i want to learn this so i can get up to make programs and apps for my electronic projects.thanks for the help.

author: Psi
author_rank: Super Contributor
timestamp: December 14, 2011, 06:44:34 am
content: There are some youtube lectures on learning C programming. They're mostly aimed at learning C for windows programming but the basic stuff is still valid for microcontroller C. And they're free.

author: IanB
author_rank: Super Contributor
timestamp: December 14, 2011, 07:13:49 am
content: Be careful of your needs before you choose a language to begin learning programming. C is quite technical and hard to grasp for a beginner, and in very few cases would you be best advised to start there.If you want to program microcontrollers like PIC and ATMEL then starting with C is definitely a possibility, but you should also consider the friendlier C-like language in the Arduino system, or various kinds of BASIC. Bear in mind that programming in C on an AVR, for example, is a very raw and unwelcoming experience.If you want to program desktop computers to interface to your electronic gadgets, then run a mile away from C as fast as you can. I would highly recommend C# and .NET on the Windows platform, and actually I don't know what if you are on Linux or Apple. In that case probably C++ or Objective C. Remember that C++ is not a "more advanced C", it is a "better, easier to use, improved C". Don't ever start with C and move on to C++, just start with C++ and drop back to C if you must later on.

author: SH@RK
author_rank: Contributor
timestamp: December 14, 2011, 07:58:50 am
content: Easy programming language but tricky most of the time .I learned it a year ago at university and this is what we learned from at my university .I do not know how to use it in electronics but for basics this link is very good .http://faculty.kfupm.edu.sa/ics/said/teaching.htmlUse from that pageLecture Slides and Laboratory Documents .And if u have any question I can help u [ A+ student ]

author: slashguitar
author_rank: Contributor
timestamp: December 14, 2011, 10:35:43 am
content: Embedded C. by Michael J. Pont was the first book I read about embedded programming. All the basic concepts are really well explained

author: robrenz
author_rank: Super Contributor
timestamp: December 14, 2011, 12:27:03 pm
content: I knew nothing about C and I found this sites tutorials very digestablehttp://www.cprogramming.com/tutorial.html

author: steff
author_rank: Contributor
timestamp: December 14, 2011, 01:06:08 pm
content: I can recommend Steve Oualline's "Practical C Programming". Not aimed at microcontrollers, but a good overview of the language.

author: doctorm
author_rank: Regular Contributor
timestamp: December 14, 2011, 04:22:40 pm
content: thanks everyone for the help so far.i think i should add that im not planning on using C very much for my projects but for just to help me get acquainted with programming in general.in the future im also insterested in programming for android devices.so if C is not the best choice to start off with, then what is the best one to start with to get up to where i need? keep in mind i just want to practice and get better with programming in general.

author: IanB
author_rank: Super Contributor
timestamp: December 14, 2011, 04:34:42 pm
content: Quote from: doctorm on December 14, 2011, 04:22:40 pmIf you want to learn programming in general, then as I mentioned above C# would be a good choice. You can download Visual C# Express for free from Microsoft.

author: kaz911
author_rank: Super Contributor
timestamp: December 14, 2011, 04:48:19 pm
content: to be honest - C is the "simplest" language and should be in the tool-chest of every programmer.I'm not a good C programmer - but I do know enough to write code. And since most embedded code is not very dependent on external libraries for graphics etc - most things are quite simple and quite logical.If you go to C# or C++ it becomes more complex (and easier in other ways).Start with Arduino C - it is cheap and easy to get started with - and lots of tutorials online and plenty of videos on youtube.

author: steff
author_rank: Contributor
timestamp: December 14, 2011, 07:10:01 pm
content: Quote from: doctorm on December 14, 2011, 04:22:40 pmWell, Android is all Java (albeit on the Dalvik JVM rather than Sun's one). However, speaking as someone who works with a lot of developers but isn't primarily one myself I'd caution against learning Java too early. A lot of undergraduate courses use it now and it seems to promote a very dysfunctional view of how computers actually work outside the JVM which takes a lot of bitter experience to unlearn. I'd imagine that as a class-library-orientated OO language with a big honkin' VM a lot of this would apply to C# too, though I have no direct experience of it.C is a pretty good language for learning how things actually work, simply because the representation you're working in maps quite closely onto the representation the microprocessor will eventually see (especially if you're writing it in an space and speed-restricted context and bit-banging things rather than using lots of libraries to abstract away all the low-level details). A brief foray or two into assembler is also very useful for this, albeit it's more or less the least productive language imaginable for doing whole projects in.Away from microcontrollers, Python and Ruby are often advanced as good "starter" languages. I'm just old enough that I learned Perl instead and have never seen a particularly persuasive reason to convert to the newer scripting languages. In my job (running infrastructure) it's also very useful that perl is available by default on pretty much any UNIX/Linux machine made in living memory.

author: McMonster
author_rank: Frequent Contributor
timestamp: December 14, 2011, 08:00:04 pm
content: Quote from: steff on December 14, 2011, 07:10:01 pmProblem with Java is not what people learn but rather what they do not learn using it. It's also very popular because it fits the "we assume people are dumb and shield them from thinking" scheme as it protects the programmer from most of the usual traps of classic languages and this approach makes them unable to produce good code in any of the classical languages. It's not inherently bad, but it's certainly overused in the industry in many areas.I would also recommend C as a starting language to anyone serious about programming. It's a good starting point and has everything a good programmer needs to learn. And it's basically the only real choice for someone interested in embedded applications.A side not about the last sentence, I once had an embedded programming course on my university... taught in Java.We've only seen a microcontroller on a single basic functional diagram and we've been programming STBs with embedded Linux running Java Xlets (Wikipedia for more info). The course was worth nothing.

author: bfritz
author_rank: Regular Contributor
timestamp: December 14, 2011, 08:35:32 pm
content: C is probably the best "high level" language to learn, if you want to learn about micro's, and how they work.If you really want to learn how the hardware functions, then assembly is the tool. The C will cross-compile to assembly language. Assembly language shields you from nothing, so you end up learning everything. But, assembly is a difficult place to start learning programming.With that said, I would recommend for someone who has never programmed before that C++ is a great starting place. I would pick up a book that teaches C++, as C++ is a superset of C, and any good book on C++ will teach you how C and C++ differ while teaching you the language.

author: McMonster
author_rank: Frequent Contributor
timestamp: December 14, 2011, 08:48:24 pm
content: Assembly languages still have macroinstructions and assemblers still do some work for the programmer (like converting hex numbers to binary). It may seem like nothing, but there are people who don't know how to convert numbers for example. Just my 0.03$, but I agree generally.C++ is a vast topic in itself and honestly I haven't seen a really good book in that it teaches you about the differences, just one that attempted that with some success, so I'd still stick to C and then moving to C++ if needed.

author: DaMaDo
author_rank: Contributor
timestamp: December 15, 2011, 04:48:06 am
content: Is there a reason you want C over C++?I ask because I just took an intro to C for my Mech Eng program and I much preferred C++ over C and C#.I'm not sure how accurate the professor was, but he explained that C++ is the evolution of C..like C version 3.0 etc. Whereas C# and all the others are like different product lines. cin/cout in C++ is really nice.I don't like the Processing language of Arduino...I'd rather just learn the regular C++ commands since it's useful for other things also.C# is great to create nice looking windows programs very easily.A great book for C++ is "C++ Primer Plus" by Steven Prata

author: joelby
author_rank: Frequent Contributor
timestamp: December 15, 2011, 06:57:13 am
content: For 8- and 16-bit processors, C++ compilers are very rare indeed.C++ isn't precisely a 'newer' version of C, but rather an object orientated superset.Object orientation hardly makes sense for embedded development, where you are typically unable to allocate much memory dynamically, and you just run a bunch of stuff in a loop or from interrupt as quickly as possible.

author: kaz911
author_rank: Super Contributor
timestamp: December 15, 2011, 11:13:13 am
content: Quote from: DaMaDo on December 15, 2011, 04:48:06 amC++ is not a new version of C. It is a different version of C with Object Oriented Design. Since no processor has true Object definitions - C is "closer" to the hardware and assembler. The distance from C to Assembler is "small" - the distance from C++ to Assembler is a lot bigger. The distance from C# to Assembler is HUGE.So if you want to learn why your hardware is doing what it is doing... C is the "closest" you get without writing Assembly code. And if you know C - C++ or C# are just "additions"Just try to run a disassembler on a piece of C++ object code - and try to find each C++ line in the "disassembled" code. That can be very hard especially if you have inherited objects etc. Do the same on some pure ANSI C / KR C code and you can more or less map - line by line(s) - each statement from your C coding. If you disable compiler optimizations it is even easier.So for first steps in Embedded - and to get to know your hardware C is great. (Assembler is still better - but not to many people learns Assembler any longer)Once you know your hardware and compiler and how it "throws" things around in the optimizations etc. C++ and other languages are great.But if you started with Java and want to "upgrade" then start with C++. Else it can feel a bit constrained working in pure C without objects.The "Sharp" (C#,F#,J#) products are also great - but usually very limited support for execution outside of Microsoft environments. There are some support but usually the support is a few generations behind and might not support all functions (Mono on OSX or Linux)As a programmer you should not be limited to a single language. A language is a tool - just like a screwdriver. And then you pick the RIGHT tool for the RIGHT task.My "main" tools are C#, C, Erlang and Python - and each have their good and bad sides and are used for different things. C# for GUI on Windows (with some experiments on OSX) - C for high performance single threaded apps and Erlang for giga multithreaded multi machine distributed apps. And Python for all the rest..

author: MikeK
author_rank: Super Contributor
timestamp: December 15, 2011, 03:58:32 pm
content: The old standby is "The C Programming Language" by Kernighan and Ritchie. Ritchie created the C programming language and, if memory serves, the book contains examples to work through.

author: ColinA
author_rank: Contributor
timestamp: December 15, 2011, 04:50:57 pm
content: An excellent book aimed towards the avr is "Embedded C Programming and the Atmel AVR".Little expensive but well worth it.

author: A-sic Enginerd
author_rank: Regular Contributor
timestamp: December 15, 2011, 05:13:13 pm
content: Quote from: MikeK on December 15, 2011, 03:58:32 pm^^^ This.I don't know of a single software engineer that doesn't own a copy of this someplace in their library. You don't get much more basic than this. All versions of C have their roots here.Also, realize the distinction between "learning C" and "learning programming". Grab a book and you can learn the language. If you truly want to learn proper programming, take a couple undergrad level classes. Look for courses with a title of something like "Programming Concepts and Methodologies" or some such bs. What you learn there will be language agnostic and will go a long way. With limitations of embedded systems, these fundamental understandings can save a lot of headache later on.