Friday, February 18, 2011

Breaking up lines\ is easy to do part3

Author: Joe
Partner: dvd ripper

To wit, change Lines 10 and 11 in the source code from this:


printf(“C is done mostly in lowercase.\
It’s a case-sensitive language.”);

to this:
printf(“C is done mostly in lowercase. \
It’s a case-sensitive language.”);


Note the extra space after the period in the first line (before the backslash), which keeps the two lines of text from running into each other. Save that mess. Compile and run. The output shall be most pleasing to the eye.


Do note that some programs elsewhere in this book may use the \ to split long lines.


Don’t worry about using the \ to split any lines. It’s a trick you see others use occasionally, but in my travels I prefer using a sideways-scrolling editor to splitting up long lines.


Although split lines are treated as a single line, any errors that happen on either line are given their proper line number in the source code file. So, if a semicolon were missing at the end of Line 11 in the RULES.C example, the compiler would flag it on that line, not on the line before it.

See also:

http://clanguage86.blogspot.com/2011/01/four-steps-to-build-c-program.html

http://clanguage86.blogspot.com/2011/01/5-steps-to-reedite-your-c-source-code.html

http://clanguage86.blogspot.com/2011/01/what-meaning-of-recompiling-c-program.html

Breaking up lines\ is easy to do part2

Author: Joe
Partner: dvd to mp3

 

Depending on how your editor and compiler behave, the result of splitting a line with a string of text in it may not be what you want. For example, the output on your screen may look like this:


Braces come in pairs!
Comments come in pairs!
All statements end with a semicolon!
Spaces are optional!
Must have a main function!
C is done mostly in lowercase.  It’s a case-
sensitive language.


That happens because the split line includes a few tabs to indent things - which looks pretty in your source code, but looks like blech when the pro­gram runs. The solution is merely to edit the source code so that the extra tabs are removed from the string of text.

 

See also:

http://clanguage86.blogspot.com/2011/01/compiler-and-linker.html

http://clanguage86.blogspot.com/2011/01/how-to-compile-goodbyec.html

http://clanguage86.blogspot.com/2011/01/extra-help-in-typing-goodbyec-source.html

Breaking up lines\ is easy to do part1

Author: Joe
Partner: dvd to mp3

 

Another anomaly of the RULES program is that rogue \ character found at the end of the tenth line. When used to end a line, the sole \ tells the compiler that the rest of the line is merely continued on the line that follows. So, these two lines:


printf(“C is done mostly in lowercase\
It’s a case-sensitive language.\n”);


are both seen as one single line when it comes time to compile; all the compiler sees is this:

printf(“C is done mostly in lowercase It’s a case-sensitive
language.\n”);

You may find such a trick necessary for extra-long lines as your programs grow
more complex. The \ simply lets you split up a long line between several lines
in your source code. That can be handy.

 

See also:

http://clanguage86.blogspot.com/2011/01/source-file-and-goodbyec-practice.html

http://clanguage86.blogspot.com/2011/01/c-development-cycle-and-c-programmer.html

http://clanguage86.blogspot.com/2011/01/stuff-you-dont-need-to-know-about.html

Friday, February 11, 2011

6 unkonwn C language components

The C language has many other parts, making it look rather bizarre to the new programmer. Right now, all that’s standing between ignorance and knowledge is time, so don’t dwell on what you don’t know. Instead, keep these few points rolling around in your mind, like so many knowledge nuggets:

The C language uses words — keywords, functions, and so forth — as its most basic elements.

Included with the words are symbols. Sometimes these symbols are called operators, and at other times they’re called something else. For example, the plus sign (+) is used in C to add things.

The words have options and rules about how they’re used. These rules are all referenced in the C reference material that came with your compiler. You don’t have to memorize all of them, though a few of them become second nature to you as you study and use C.

Parentheses are used to group some of the important items required by C words. The words are put together to create statements, which are similar to sentences in English. The statements all end with a semicolon.

Braces are used to group parts of a program. Some words use braces to group their belongings, and all the separate functions you create within a program are grouped by braces. The braces have been used to con­tain the belongings of the main() function.

All this stuff put together (and more stuff I dare not discuss at this point) makes up the syntax of the C language. Syntax is how languages are put together.

Passage reproduced from:http://clanguage86.blog.co.in/2011/02/11/6-unkonwn-c-language-components/

See also:

The Four Steps to build a C program

5 steps to reedite your C source code file

What's the meaning of recompiling the C program?

Sponsor:DVD Rippers

5 quizzes about C language! Take the challenge!

Hey, guys, here are 5 quiz about C language, normally 90% of people that take the quiz beblow can only get 4 of them right. Out of another 10%, there are only less than 5% can get them all right. Take the challenge and see if you can get them all right. Good luck.

1.  The core function in every C language program is called
A. numero_uno().
B. main().
C. primus().
D. core().


2.  C language keywords are
A. The “words” of the C language.
B. Held together with string and earwax.
C. Uttered only in candlelit reverence by the C Language Gurus.
D. As numerous as the stars and nearly as distant.


3.  In addition to keywords are
A. Functions, such as printf().
B. Operators, such as +, -, and other weird things.
C. Curly braces or brackets, angle brackets — all sorts of brackets. Man, do we have a bracket problem!
D. Probably all of the above.


4.  Functions require parentheses because
A. They talk in whispers.
B. The parentheses keep the function warm.
C. The parentheses hold various things required by or belonging to the function.
D. What’s a function?


5.  A telltale sign of any C program is its curly braces. Using what you know of
C, draw in the braces where they should appear in the following program:
int main()
printf(“Goodbye, cruel world!\n”);
return(0);

I will give the answers in later post of this blog. So keep an eye on this blog.

Passage reproduced from:http://clanguage86.blog.co.in/2011/02/11/5-quizzes-about-c-language-take-the-challenge/

See also:

What to do when you come across an error?

The autopsy Part1

The autopsy Part2

Sponsor:DVD Ripper

Practice! A helpful rules program

To help you under­ stand the most easily offended C rules, I have summarized them in the follow­ing program. It displays several lines of text that remind you of the basic rules of C that you know about:
#include <stdio.h>
int main()
{
printf(“Braces come in pairs!”);
printf(“Comments come in pairs!”);
printf(“All statements end with a semicolon!”);
printf(“Spaces are optional!”);
printf(“Must have a main function!”);
printf(“C is done mostly in lowercase.\
It’s a case-sensitive language.”);
return(0);
}
Type the preceding source code into your editor. Save the code to disk as RULES.C. Compile and run.


The resulting program is named RULES, and you can run it whenever you need a reminder about some basic C do’s and don’ts.


This program is really no different from those shown in previous blog posts. It merely has more printf() functions.

The final printf() function (in Line 10) may seem a little odd. That’s because it’s split between two lines. This weird contraption is covered
later in later blog post.

See also:

Extra help in typing the GOODBYE.C source code

The compiler and the linker

How to compile goodbye.c?

Sponsor:DVDs Ripper