source - http://www.cprogramming.com/tips/
Friday, October 25, 2013
How to Learn to Program in C
How to Learn to Program in C
Edited by Eshafer, Nicole Willson, Vikram Kumar Rohra, Horses4Ever and 27 others
C is a powerful programing language that was first developed in the 1970's. Depending on your previous programming experience, it may take time and patience to learn C. However, once learned, learning other programming languages will come naturally. While learning the entire language is beyond the scope of this article, it will get you started in the right direction.
EditSteps
- 1First find a compiler that is compatible with your operating system, and decide whether you want to run an Integrated Development Environment (IDE) or if you want to edit C files manually through an editor like Notepad and compile from the command line.
- If you're a Windows user, try using Visual C++ Express Edition which is available for download for free.
- If you're a Mac user, you can use Xcode, available from the Leopard install disk or the App Store for free.
- If you're a GNU/Linux user, try KDevelop or Eclipse. Eclipse is also available for Windows.
- Alternatively, you can use the command line tools (GCC runs under any Unix and it is possible to run it under Windows and Mac).
- Tiny C Compiler (TCC) is great if you don't want to get a ton of bells and whistles that come with other compilers
-
2Learn how to compile and run a basic program, this will be your first program, typically it will just print "Hello World" to the screen and exit. Don't worry about all the minor details of the syntax, just become comfortable with compiling and running.
-
3Learn about variable types, such as the difference between char, int, float, double, etc.
-
4Learn about the concept of variables, arrays and functions. Variables are where information is stored, functions are pieces of code that can be executed and arrays are groups of data of the same type.
-
5Learn pointers. Pointers are very important in C since you can directly access memory contents through pointers, unlike Java. The drawback to this is that if your program isn't thoroughly tested, it can crash.
-
6Learn conditional statements, such as the "if" and "switch" statements. The "if" statement will be one of your most frequently used statements, you can execute code based on whether a condition is true or not (e.g. whether the color the user provided was red).
-
7Learn loops. Learn the difference of the "for" loop and the "while" loop - make sure to avoid infinite loops! Learn the continue and break statements.
-
8Learn data structures. Although data structures are not directly related to programming, but for an advanced user, knowledge of basic concepts in Computer Science is essential.
-
9Start with small programs. When you are making your own code, try to identify the most essential part of the problem - is it the data input or the calling of the functions, the structure of the loop (these are some very elementary examples) and start from there. Then build upon that in small increments.
-
10Learn key steps about debugging. Although it looks little complicated in the beginning, but if you have a large source code, then using print statements gets little overwhelming.
- 11Enroll yourself in some of the mailing lists online. You can post your own of questions and support other new users.
- 12Remember, the key to learning anything new is perseverance & hard work.
EditSample Code
Function to calculate the greatest common divisor (using the euclidean algorithm):
int gcd(int u, int v)
{
int r;
while (v != 1)
{
r = u % v;
u = v;
v = r;
}
return u;
}
The function takes two integers named 'u' and 'v' and returns an integer. The function has the name 'gcd'.
Function to calculate xy:
int power(int x, int y)
{
int result = -1
;
int i;
for(i = 1; i < y; i++)
result *= x;
return result;
}
The function takes two integers named 'x' and 'y' and returns an integer. The function has the name 'power'.
EditTips
- Your source code needs to have a *.c extension, so that your compiler can understand that it's a C source file.
- Find a good C programming book. A recommendable C resource book is "The C Programming Language" by Brian W. Kernighan, Dennis Ritchie (ISBN 0131103628 - You can a free electronic copy of the original draft here). Find a book that has tutorials and projects to facilitate your exposure to C.
- Always add comments to your programs. Not only does this help others who might take a look at its source code, but also it helps you remember what you're writing and why. You may know what you're doing the moment that you're writing your code, but after two or three months, you won't remember much.
- Don't try to avoid mistakes; embrace them. Making mistakes is the most important part in learning how to programm.
- Remember, C is a programming language. Learning a programming language may not necessarily lead to learning to program, which is more about problem solving than about compiling and running a program in a specific language.
- When encountering a syntax error when compiling, if you're stumped, search Google (or another search engine) with the error you received. Chances are someone has already experienced the same problem and posted a solution. source - http://www.wikihow.com/Learn-to-Program-in-C
Apple's 'Next Big Thing' - Get Updated
Apple's 'Next Big Thing' Will Be an Innovation, Not an Invention
Lots of people are wondering what Apple will invent next. If it’s true to its own history, it won’t invent a new type of product but will improve on one someone else already brought to market.
I’ve never questioned that Apple is an innovator. Its iPod, iPhone and iPad were all very innovative products. But all of them were improvements of other companies’ products or concepts in the same categories.
The iPod, introduced in October 2001, was not the first digital music player. Diamond Multimedia announced the Rio PMP 300 in 1998, and the Creative Nomad Jukebox and Archos Jukebox came out in 2000. None of these products would have been possible were it not for innovations in storage, compression and battery life from scores of scientists and inventors.
Apple did a great job by combining the hardware with its iTunes software and its music store. And that, plus Steve Jobs’ brilliant marketing, is why the iPod soon became the dominant music player.
The iPhone, which came out in 2007, was far from the first smartphone. Depending on how you define “smart,” there were products from PSiAn, Symbian,Nokia and of course Research In Motion (now BlackBerry), which debuted in 1999. The first Android phone didn’t hit the street until 2008, but the open-source version of the Android operating system — backed by Google – was introduced in 2003 by Andy Rubin, who just recently stepped down as Android head at Google.
Microsoft Windows Mobile came out years before the iPhone. Apple wasn’t even the first company to come out with a touch-screen smartphone. That honor goes to the IBM Simon Personal Communicator that was first introduced in 1992.
But, as with the iPod, Apple did it right. It was the first touch-screen smartphone to be highly useful. Sure, there was a lot of hype, but the phone earned that hype by delighting millions of users and becoming the gold standard by which other phones continue to be judged. Even now, when BlackBerry, Samsung or anyone else introduces a new smartphone, reviewers immediately compare it to Apple’s most recent iPhone.
The iPad, which first came out in 2010, was also an incredibly innovative product. But there were plenty of tablets on the market from a variety of companies going back more than 10 years. I was at the Comdex computer trade show in November 2001 when Bill Gates announced Windows software for the tablet PC. Gates at the time predicted that the tablet would become the most popular form of PC within five years. That was more than nine years ahead of the Apple iPad.
Microsoft’s early attempts at tablet operating systems were a bust. But after Apple reinvented the category, Microsoft is at it again with its Windows 8 operating system and its own Surface tablets. Apple does get credit for introducing the Newton MessagePad in 1992. It failed but it was an early example of a tablet-like personal digital assistant.
For a bit of perspective on tablet computers, scroll down to view the 1994 video about the “Tablet Newspaper” from a design lab at Knight Ridder, which at the time was the parent company of the San Jose Mercury News and other newspapers. What you’ll see in this 13 minute video is a tablet with a lot of features that ultimately appeared in the iPad. Of course, Knight Ridder never actually marketed the device so, once again, Apple deserves the credit for turning a good idea into a great product.
So when thinking about what Apple will do next, look around at products that already exist but could use some major improvements. Some say it will be a “smart” watch. Indeed, there are already plenty of those on the market but none are blockbuster products. It could be an Internet-connected “smart” TV if Apple can find a way to greatly improve on what other companies have done, including Samsung, Sony and LG.
Apple could also put its toe in the home automation arena, competing with lots of smaller companies. Might Apple try to compete with LG’s “smart” refrigerator? I doubt it, but I do hope Apple will try its hand at automotive products. I don’t expect to see an iCar anytime soon, but an iDash entertainment/communications/navigation unit would be a feasible and welcome competitor to all the not-so-great systems already on the market.
So let’s hope CEO Tim Cook, along with Apple’s engineers and designers, are busy looking around at other companies’ promising products that don’t quite meet up to Apple’s high standards. Apple doesn’t have to create new categories to change the world — it just has to build products that people love and then convince us that we can’t live without them.
Subscribe to:
Posts (Atom)