Search
Thursday, June 18, 2009
c++
main(){int no[10];int k,j,i,temp=0;for(k=0;k<10;k++){printf(" k="0;k<10;k++){for(j="k+1;j<20;j++){if(no[k]">no[j]){temp=no[k];no[k]=no[j];no[j]=temp;}}}printf("\n the sorted numbers in ascording order are \n ");for(i=0;i<10;i++){printf("\n %d ",no[1]);}getch();}
Option Meaning
A circumflex at the start of the expression matches the start of a
line.
$ A dollar sign at the end of the expression matches the end of a
line.
. A period matches any character.
* An expression followed by an asterisk wildcard matches zero or more
occurrences of that expression. For example, in to*, the * operates
on the expression o; it matches t, to, too, etc. (t followed by zero
or more os), but doesn't match ta.
+ An expression followed by a plus sign matches one or more
occurrences of that expression: to+ matches to, too, etc., but not
t.
[ ] A string enclosed in brackets matches any character in that string,
but no others. If the first character in the string is a circumflex
(^), the expression matches any character except the characters in
the string.
For example, [xyz] matches x, y, or z, while [^xyz] matches a and b,
but not x, y, or z. You can specify a range of characters with two
characters separated by a hyphen (-). These can be combined to form
expressions (like [a-bd-z?], which matches the ? character and any
lowercase letter except c).
\ The backslash escape character tells GREP to search for the literal
character that follows it. For example, \. matches a period instead
of "any character." The backslash can be used to quote itself; that
is, you can use \\ to indicate a literal backslash character in a
GREP expression.
line.
$ A dollar sign at the end of the expression matches the end of a
line.
. A period matches any character.
* An expression followed by an asterisk wildcard matches zero or more
occurrences of that expression. For example, in to*, the * operates
on the expression o; it matches t, to, too, etc. (t followed by zero
or more os), but doesn't match ta.
+ An expression followed by a plus sign matches one or more
occurrences of that expression: to+ matches to, too, etc., but not
t.
[ ] A string enclosed in brackets matches any character in that string,
but no others. If the first character in the string is a circumflex
(^), the expression matches any character except the characters in
the string.
For example, [xyz] matches x, y, or z, while [^xyz] matches a and b,
but not x, y, or z. You can specify a range of characters with two
characters separated by a hyphen (-). These can be combined to form
expressions (like [a-bd-z?], which matches the ? character and any
lowercase letter except c).
\ The backslash escape character tells GREP to search for the literal
character that follows it. For example, \. matches a period instead
of "any character." The backslash can be used to quote itself; that
is, you can use \\ to indicate a literal backslash character in a
GREP expression.
Option Meaning
-c Match Count only: Prints only a count of matching lines. For each file
that contains at least one matching line, GREP prints the file name and
a count of the number of matching lines. Matching lines are not
printed. This option is off by default.
-d Search subdirectories: For each file specified on the command line,
GREP searches for all files that match the file specification, both in
the directory specified and in all subdirectories below the specified
directory. If you give a file without a path, GREP assumes the files
are in the current directory. This option is off by default.
-i Ignore case: GREP ignores upper/lowercase differences (case folding).
When this option is on, GREP treats all letters a to z as identical to
the corresponding letters A to Z in all situations. This option is on
by default.
-l List file names only: Prints only the name of each file containing a
match. After GREP finds a match, it prints the file name and processing
immediately moves on to the next file. This option is off by default.
-n Line Numbers: Each matching line that GREP prints is preceded by its
line number. This option is off by default.
-o UNIX output format: Changes the output format of matching lines to
support more easily the UNIX style of command-line piping. All lines of
output are preceded by the name of the file that contained the matching
line. This option is off by default.
-r Regular expression search: The text defined by searchstring is treated
as a regular expression instead of as a literal string. This option is
on by default. This option is on by default.
A regular expression is one or more occurrences of one or more
characters optionally enclosed in quotes. The following symbols are
treated specially:
^ start of line $ end of line
- 14 -
. any character \ quote next character
* match zero or more + match one or more
[aeiou0-9] match a, e, i, o, u, and 0 thru 9
[^aeiou0-9] match anything but a, e, i, o, u, and 0 thru 9
-u Update options: GREP will combine the options given on the command line
with its default options and write these to the GREP.COM file as the
new defaults. (In other words, GREP is self-configuring.) This option
allows you to tailor the default option settings to your own taste. If
you want to see what the defaults are in a particular copy of GREP.COM,
type
GREP ?
at the DOS prompt. Each option on the help screen will be followed by a
+ or a - depending on its default setting. This option is off by
default.
-v Nonmatch: Prints only nonmatching lines. Only lines that do not contain
the search string are considered to be nonmatching lines. This option
is off by default.
-w Word search: Text found that matches the regular expression is
considered a match only if the character immediately preceding and
following cannot be part of a word. The default word character set
includes A to Z, 0 to 9, and the underscore ( _ ). This option is off
by default.
An alternate form of this option lets you specify the set of legal word
characters. Its form is -w[set], where set is any valid regular
expression set definition.
If you define the set with alphabetic characters, it is automatically
defined to contain both the uppercase and lowercase values for each
letter in the set (regardless of how it is typed), even if the search
is case-sensitive. If you use the -w option in combination with the -u
option, the new set of legal characters is saved as the default set.
-z Verbose: GREP prints the file name of every file searched. Each
matching line is preceded by its line number. A count of matching lines
in each file is given, even if the count is zero. This option is off by
default.
that contains at least one matching line, GREP prints the file name and
a count of the number of matching lines. Matching lines are not
printed. This option is off by default.
-d Search subdirectories: For each file specified on the command line,
GREP searches for all files that match the file specification, both in
the directory specified and in all subdirectories below the specified
directory. If you give a file without a path, GREP assumes the files
are in the current directory. This option is off by default.
-i Ignore case: GREP ignores upper/lowercase differences (case folding).
When this option is on, GREP treats all letters a to z as identical to
the corresponding letters A to Z in all situations. This option is on
by default.
-l List file names only: Prints only the name of each file containing a
match. After GREP finds a match, it prints the file name and processing
immediately moves on to the next file. This option is off by default.
-n Line Numbers: Each matching line that GREP prints is preceded by its
line number. This option is off by default.
-o UNIX output format: Changes the output format of matching lines to
support more easily the UNIX style of command-line piping. All lines of
output are preceded by the name of the file that contained the matching
line. This option is off by default.
-r Regular expression search: The text defined by searchstring is treated
as a regular expression instead of as a literal string. This option is
on by default. This option is on by default.
A regular expression is one or more occurrences of one or more
characters optionally enclosed in quotes. The following symbols are
treated specially:
^ start of line $ end of line
- 14 -
. any character \ quote next character
* match zero or more + match one or more
[aeiou0-9] match a, e, i, o, u, and 0 thru 9
[^aeiou0-9] match anything but a, e, i, o, u, and 0 thru 9
-u Update options: GREP will combine the options given on the command line
with its default options and write these to the GREP.COM file as the
new defaults. (In other words, GREP is self-configuring.) This option
allows you to tailor the default option settings to your own taste. If
you want to see what the defaults are in a particular copy of GREP.COM,
type
GREP ?
at the DOS prompt. Each option on the help screen will be followed by a
+ or a - depending on its default setting. This option is off by
default.
-v Nonmatch: Prints only nonmatching lines. Only lines that do not contain
the search string are considered to be nonmatching lines. This option
is off by default.
-w Word search: Text found that matches the regular expression is
considered a match only if the character immediately preceding and
following cannot be part of a word. The default word character set
includes A to Z, 0 to 9, and the underscore ( _ ). This option is off
by default.
An alternate form of this option lets you specify the set of legal word
characters. Its form is -w[set], where set is any valid regular
expression set definition.
If you define the set with alphabetic characters, it is automatically
defined to contain both the uppercase and lowercase values for each
letter in the set (regardless of how it is typed), even if the search
is case-sensitive. If you use the -w option in combination with the -u
option, the new set of legal characters is saved as the default set.
-z Verbose: GREP prints the file name of every file searched. Each
matching line is preceded by its line number. A count of matching lines
in each file is given, even if the count is zero. This option is off by
default.
The general command-line syntax for GREP is
grep [options] searchstring [file(s) ... ]
options consist of one or more letters, preceded by a
hyphen (-), that let you change various aspects of
GREP's behavior.
searchstring gives the pattern to search for.
file(s) tells GREP which files to search. (If you don't
specify a file, GREP searches its standard input; this
lets you use GREP with pipes and redirection.) If you
find that the results of your GREP are longer than one
screen, you can redirect the output to a file. For
example, you could use this command
GREP "Bob" *.txt >gfile
which searches all files in the current directory that
end with .TXT, then places the results in a file called
GFILE. (You can name this file anything you like.)
Then, use your word processor (or Turbo C++'s editor)
to access GFILE to read the results of the search.
The command
GREP ?
prints a brief help screen showing GREP's command-line
options, special characters, and defaults. (See the
description of the -u command-line option for
information on how to change GREP's defaults.)
GREP options =======================================================
In the command line, options are one or more single
characters preceded by a hyphen (-). Each individual
character is a switch that you can turn on or off: A
plus symbol (+) after a character turns the option on;
a hyphen (-) after the character turns the option off.
The + sign is optional; for example, -r means the same
thing as -r+. You can list multiple options
- 13 -
individually (like this: -i -d -l), or you can combine
them (like this: -ild or -il, -d, and so on); it's all
the same to GREP.
Here are the GREP option characters and their meanings:
options consist of one or more letters, preceded by a
hyphen (-), that let you change various aspects of
GREP's behavior.
searchstring gives the pattern to search for.
file(s) tells GREP which files to search. (If you don't
specify a file, GREP searches its standard input; this
lets you use GREP with pipes and redirection.) If you
find that the results of your GREP are longer than one
screen, you can redirect the output to a file. For
example, you could use this command
GREP "Bob" *.txt >gfile
which searches all files in the current directory that
end with .TXT, then places the results in a file called
GFILE. (You can name this file anything you like.)
Then, use your word processor (or Turbo C++'s editor)
to access GFILE to read the results of the search.
The command
GREP ?
prints a brief help screen showing GREP's command-line
options, special characters, and defaults. (See the
description of the -u command-line option for
information on how to change GREP's defaults.)
GREP options =======================================================
In the command line, options are one or more single
characters preceded by a hyphen (-). Each individual
character is a switch that you can turn on or off: A
plus symbol (+) after a character turns the option on;
a hyphen (-) after the character turns the option off.
The + sign is optional; for example, -r means the same
thing as -r+. You can list multiple options
- 13 -
individually (like this: -i -d -l), or you can combine
them (like this: -ild or -il, -d, and so on); it's all
the same to GREP.
Here are the GREP option characters and their meanings:
GREP: A text-search utility
GREP (Global Regular Expression Print) is a powerful
text-search program derived from the UNIX utility of
the same name. GREP searches for a text pattern in one
or more files or in its standard input stream.
Here's a quick example of a situation where you might
want to use GREP. Suppose you wanted to find out which
text files in your current directory contained the
string "Bob". You would issue the command
grep Bob *.txt
and GREP would respond with a list of the lines in each
file (if any) that contained the string "Bob". Because
the default for GREP is to ignore case, the strings
"bob" and "BoB" would also be considered matches. You
can use options to make your search case sensitive.
GREP can do a lot more than match a single, fixed
string. In the section that follows, you'll see how to
make GREP search for any string that matches a
particular pattern.
text-search program derived from the UNIX utility of
the same name. GREP searches for a text pattern in one
or more files or in its standard input stream.
Here's a quick example of a situation where you might
want to use GREP. Suppose you wanted to find out which
text files in your current directory contained the
string "Bob". You would issue the command
grep Bob *.txt
and GREP would respond with a list of the lines in each
file (if any) that contained the string "Bob". Because
the default for GREP is to ignore case, the strings
"bob" and "BoB" would also be considered matches. You
can use options to make your search case sensitive.
GREP can do a lot more than match a single, fixed
string. In the section that follows, you'll see how to
make GREP search for any string that matches a
particular pattern.
This output file is a text file containing each line
This output file is a text file containing each line of
the source file and any include files. Any preproces-
sing directive lines have been removed, along with any
conditional text lines excluded from the compile.
Unless you use a command-line option to specify other-
wise, text lines are prefixed with the file name and
line number of the source or include file the line came
from. Within a text line, any macros are replaced with
their expansion text.
Important! The resulting output of CPP cannot be compiled because
of the file name and line number prefix attached to
each source line.
CPP as a macro =======================================================
preprocessor
The -P option to CPP tells it to prefix each line with
the source file name and line number. If you give it -
P- (turning this option off), CPP omits this line
number information. With this option turned off, CPP
can be used as a macro preprocessor; the resulting .I
file can then be compiled with TC or TCC.
An example =======================================================
The following simple program illustrates how CPP
preprocesses a file, first with -P selected, then with
-P-.
Source file: HELLOAJ.C
#define NAME "H.R. Floyd"
#define BEGIN {
#define END }
main()
BEGIN
printf("%s\n", NAME);
END
Command line used to invoke CPP as a preprocessor:
CPP HELLOAJ.C
Output:
HELLOAJ.c 1:
HELLOAJ.c 2:
HELLOAJ.c 3:
the source file and any include files. Any preproces-
sing directive lines have been removed, along with any
conditional text lines excluded from the compile.
Unless you use a command-line option to specify other-
wise, text lines are prefixed with the file name and
line number of the source or include file the line came
from. Within a text line, any macros are replaced with
their expansion text.
Important! The resulting output of CPP cannot be compiled because
of the file name and line number prefix attached to
each source line.
CPP as a macro =======================================================
preprocessor
The -P option to CPP tells it to prefix each line with
the source file name and line number. If you give it -
P- (turning this option off), CPP omits this line
number information. With this option turned off, CPP
can be used as a macro preprocessor; the resulting .I
file can then be compiled with TC or TCC.
An example =======================================================
The following simple program illustrates how CPP
preprocesses a file, first with -P selected, then with
-P-.
Source file: HELLOAJ.C
#define NAME "H.R. Floyd"
#define BEGIN {
#define END }
main()
BEGIN
printf("%s\n", NAME);
END
Command line used to invoke CPP as a preprocessor:
CPP HELLOAJ.C
Output:
HELLOAJ.c 1:
HELLOAJ.c 2:
HELLOAJ.c 3:
C ++ Program
// Borland C++ - (C) Copyright 1991 by Borland International
//XSTRING.CPP--Example from Getting Started */// version of STRING.CPP with overloaded operator +
#include#include
class String { char *char_ptr; // pointer to string contents int length; // length of string in characterspublic: // three different constructors String(char *text); // constructor using existing string String(int size = 80); // creates default empty string String(String& Other_String); // for assignment from another // object of this class ~String() {delete char_ptr;}; // inline destructor int Get_len (void); String operator+ (String& Arg); void Show (void);};
String::String (char *text){ length = strlen(text); // get length of text char_ptr = new char[length + 1]; strcpy(char_ptr, text);};
String::String (int size){ length = size; char_ptr = new char[length+1]; *char_ptr = '\0';};
String::String (String& Other_String){ length = Other_String.length; // length of other string char_ptr = new char [length + 1]; // allocate the memory strcpy (char_ptr, Other_String.char_ptr); // copy the text};
String String::operator+ (String& Arg){ String Temp( length + Arg.length ); strcpy(Temp.char_ptr, char_ptr); strcat(Temp.char_ptr, Arg.char_ptr); return Temp;}
int String::Get_len(void){ return (length);};
void String::Show(void){ cout << char_ptr << "\n";};
main () // test the functions{ String AString ("The Quick Brown fox"); AString.Show();
String BString(" jumps over Bill"); String CString; CString = AString + BString; CString.Show();}
//XSTRING.CPP--Example from Getting Started */// version of STRING.CPP with overloaded operator +
#include
class String { char *char_ptr; // pointer to string contents int length; // length of string in characterspublic: // three different constructors String(char *text); // constructor using existing string String(int size = 80); // creates default empty string String(String& Other_String); // for assignment from another // object of this class ~String() {delete char_ptr;}; // inline destructor int Get_len (void); String operator+ (String& Arg); void Show (void);};
String::String (char *text){ length = strlen(text); // get length of text char_ptr = new char[length + 1]; strcpy(char_ptr, text);};
String::String (int size){ length = size; char_ptr = new char[length+1]; *char_ptr = '\0';};
String::String (String& Other_String){ length = Other_String.length; // length of other string char_ptr = new char [length + 1]; // allocate the memory strcpy (char_ptr, Other_String.char_ptr); // copy the text};
String String::operator+ (String& Arg){ String Temp( length + Arg.length ); strcpy(Temp.char_ptr, char_ptr); strcat(Temp.char_ptr, Arg.char_ptr); return Temp;}
int String::Get_len(void){ return (length);};
void String::Show(void){ cout << char_ptr << "\n";};
main () // test the functions{ String AString ("The Quick Brown fox"); AString.Show();
String BString(" jumps over Bill"); String CString; CString = AString + BString; CString.Show();}
CPP: The preprocessor
CPP produces a Often, when the compiler reports an error inside a
list (in a file) macro or an include file, you can get more information
of a C source about what the error is if you can see the include
program in which files or the results of the macro expansions. In many
include files and multi-pass compilers, a separate pass performs this
#define macros work, and the results of the pass can be examined.
have been Since Turbo C++ uses an integrated single-pass compil-
expanded. It is er, we provided CPP to supply the first-pass
not needed for functionality found in other compilers.
normal compil-
ations of C You use CPP just as you would use TCC, the standalone
programs. compiler. CPP reads the same TURBOC.CFG file for
default options, and accepts the same command-line
options as TCC.
The TCC options that don't pertain to CPP are simply
ignored by CPP. To see the list of arguments handled by
CPP, type cpp at the DOS prompt. To see how those
arguments work, see Chapter 5 in the Programmer's
Guide.
With one exception, the file names listed on the CPP
command line are treated like they are in TCC, with
wildcards allowed. The exception to this is that all
files are treated as C source files. There is no
special treatment for .OBJ, .LIB, or .ASM files.
For each file processed by CPP, the output is written
to a file in the current directory (or the output
directory named by the -n option) with the same name as
the source name but with an extension of .I.
list (in a file) macro or an include file, you can get more information
of a C source about what the error is if you can see the include
program in which files or the results of the macro expansions. In many
include files and multi-pass compilers, a separate pass performs this
#define macros work, and the results of the pass can be examined.
have been Since Turbo C++ uses an integrated single-pass compil-
expanded. It is er, we provided CPP to supply the first-pass
not needed for functionality found in other compilers.
normal compil-
ations of C You use CPP just as you would use TCC, the standalone
programs. compiler. CPP reads the same TURBOC.CFG file for
default options, and accepts the same command-line
options as TCC.
The TCC options that don't pertain to CPP are simply
ignored by CPP. To see the list of arguments handled by
CPP, type cpp at the DOS prompt. To see how those
arguments work, see Chapter 5 in the Programmer's
Guide.
With one exception, the file names listed on the CPP
command line are treated like they are in TCC, with
wildcards allowed. The exception to this is that all
files are treated as C source files. There is no
special treatment for .OBJ, .LIB, or .ASM files.
For each file processed by CPP, the output is written
to a file in the current directory (or the output
directory named by the -n option) with the same name as
the source name but with an extension of .I.