Tuesday, March 1, 2011

Printing funky text using C program part 1

Author: Joe Patner:dvd ripper

 

Ladies and gentlemen, I give you the following: Ta da!  I am a text string.

It’s a simple collection of text, numbers, letters, and other characters — but it’s not a string of text. Nope. For those characters to be considered as a unit, they must be neatly enclosed in double quotes:
“Ta da!  I am a text string.”

Now you have a string of text, but that’s still nothing unless the computer can manipulate it. For manipulation, you need to wrap up the string in the bunlike parentheses: (“Ta da!  I am a text string.”)

Furthermore, you need an engine — a function — to manipulate the string. Put printf on one side and a semicolon on the other:
printf(“Ta da!  I am a text string.”);

And, you have a hot dog of a C command to display the simple collection of text, numbers, letters, and other characters on the screen. Neat and tidy.

Consider this rabble:  He said, “Ta da! I am a text string.”

Is this criminal or what? It’s still a text string, but it contains the double-quote characters. Can you make that text a string by adding even more double quotes? “He said, “Ta da! I am a text string.””

Now there are four double quotes in all. That means eight tick marks hovering over this string’s head. How can it morally cope with that?
“”Damocles” if I know.”

The C compiler never punishes you for “testing” anything. There is no large room in a hollowed-out mountain in the Rockies where a little man sits in a chair looking at millions of video screens, one of which contains your PC’s output, and, no, the little man doesn’t snicker evilly whenever you get an error. Errors are safe! So why not experiment?

 

Welcom to reproduce this passage. Please indicate the source.
Source:Seo Research Blog
Links resources:dvd to flv 

Printing funky text using C program part 2

Please enter the following source code, DBLQUOTE.C. The resulting program is another “printf() displays something” example. But this time, what’s dis­played contains a double quote. Can you do that? This source code is your experiment for the day:
#include <stdio.h>
int main()
{
printf(“He said, “Ta da! I am a text string.””);
return(0);
}

Type the source code exactly as it appears, including the double quotes — four in all. (You notice right away that something is wrong if your editor color-codes quoted text. But work with me here.)

Save the source code file to disk as DBLQUOTE.C. Compile and run the preceding program — if you can. Chances are that you encounter one of these errors instead:

dblequote.c: In function ‘main’:
dblequote.c:5: parse error before “Ta” or
dblequote.c: In function ‘main’:
dblequote.c:6: syntax error before “Ta”

The printf() function requires a text string enclosed in double quotes. Your compiler knows that. After the second double quote in the string was encoun­tered (before the word Ta), the compiler expected something else — something other than “Ta.” Therefore, an error was generated.

Obviously, there is a need to use the double-quote character in a string of text. The question is how to pass that character along to printf() without it ruin­ing the rest of your day. The answer is to use an escape sequence. In the olden days, programmers would have simply gone without certain char­acters. Rather than trip up a string with a double quote, they would have used two single quotes. Some ancient programmers who don’t know about escape sequences still use these tricks.

 

Welcom to reproduce this passage. Please indicate the author and the source.
Author: Joe          Source:Seo Research Blog
Partner:dvd to flv  converter from dvd ripper