language cyclic structure [c] [Function] [pointers] [] array on

[1]
2.
Scanf function
Return Value: number of successfully matched to the input.
1) * intermediate time write more characters to join a space.
Between a plurality of scanf () with getchar () to recover a tab or a \ n or a space
S # the include <stdio.h>
int main ()
{
char CHl;
the while (. 1)
{
Scanf ( "C%", ch1 &);
getchar (); // not to join the function can not empty the contents of the buffer zone, the value of the last input will still remain in the buffer zone, resulting in an error results.
Switch (CHl)
{
Case 'A':
the printf ( "A \ n-");
BREAK;
Case '\ n-':
the printf ( "10 \ n-");
BREAK;
// getchar ();
default:
the printf ( "OTHER \ n-");
}
// getchar ();

}



return 0;
}

[2]
1. getchar:
int getchar (void);
Function: a character from the input terminal
Parameters: None
Return Value: ASCII value of input characters
#include <stdio.h>
int main ()
{
char CH;
// Scanf ( "% C", & CH);
CH = getchar (); // for automatic conversion, is the number of letters, numbers, letters is (ASCII value)
the printf ( "% C \ n-", CH);

return 0;
}


3.getchar
[2] The character input output statement
1.getchar:
int getchar (void);
Function: a character from the input terminal
Parameters: None
Return Value: ASCII value of the character input
2.putchar:
int the putchar (C int);
function : a character to the output terminal
parameters: c: the character to be output
return value: ASCII character value of the output

Exercise: realize letters with getchar and putchar case conversion

[3] the gets:
char * the gets (char * S);
function: input string from the terminal
parameters: s: first address to the string
Return Value: first address input string

2.puts:
int the puts (const char * S);
Function: string to the output terminal
parameters: s: string output to the first address
output number of characters: Return Value

[4] control statements:
1. branch statement: IF ... the else
. 1) Basic format:
IF (expression)
{
statement block. 1;
}
the else
{
statement block 2;
}
execution order: first determining expression is satisfied, if true, execute statement blocks 1, 2 or The statements
2) hierarchy:
IF (expression 1)
{
block of statements 1;
}
the else IF (expression 2)
{
block of statements 2;
}
the else
{
statement block 3;
}
the order of execution: determining whether an expression is established, the establishment of a block of statements executed, otherwise the expression 2 is determined, if the establishment of The statements 2; else the expression 3
3) nested structure:
iF (expression 1)
{
iF ( expression 2)
{
block of statements 1; // expression 1 expression 2 &&
}
the else
{} block of statements 2 // expression 1 expression 2 is not satisfied &&
}
the else
{
IF (expression 3)
@ 3} {statement block expression 1 is not satisfied Expression 3 &&
the else
{} block of statements 4 // && expression 1 is not satisfied Expression 3 is not satisfied
}


Note: 1.if else can not, but must above else IF
almost continuousl and else no intervening spacer
3. If no matching braces next statement only

 


[5] branch switch ... case statement
format:
Switch (expression)
{
Case 1 constants:
a block of statements;
BREAK;
Case 2 constants:
a block of statements;
BREAK;
default:
statement block;
BREAK;
}
// if the latter statement block after executing the now not-so break the blocks continue to the next one.
Note: The expression can not be floating-point types and strings
break after default may be omitted
constants must be integer constants and character constants, not a floating-point constants

continue & break

continue: the end of this cycle, the next cycle continues to
break: the end of the cycle, only the end of one cycle.

continue distinction while () & for () of

For example:
#incldue <stdio.h>
int main ()
{
int I = 0;
the while (I <100)
{
IF (I% 2 == 0)
{
Continue;
}
I ++;
}
return 0;
}
In the above procedure It will enter an infinite loop. Because when performing the if statement inside the block, this cycle will end, while inside the direct jump is not performed i ++;
for example:
#incldue <stdio.h>
int main ()
{
int I = 0;
for (I = 0; i <100; i ++)
{
IF (i% 2)
{
Continue;
}
}
return 0;
}
the above procedure does not enter an infinite loop, continue directly for loop a value at time i updated until i> = 100 when the program ends;

 


[6] loop:
1.For cycle:
Format:
for (Expression 1; 2 Expression; Expression 3)
{
block of statements;
}
execution order:
Expression 1: assignments - the initial value of
expression 2: Analyzing statement - the final value of
expression 3: impairment of value-added or statements
to execute an expression 1, expression 2 and then determine whether the establishment, if the establishment of the execution cycle, then execute the expression 3, to determine the expression 2, followed by cycle until the expression Equation 2 is not satisfied, the loop ends
Note: expression 1 can be omitted, if need be omitted expression written on the cycle of
expression 3 can be omitted, omitted the words need to be written expression in a loop
expression 2 can not be omitted, omitted words endless loop
for loop represents infinite loop: for (;;); for ( ;;); while (1);

 

Guess you like

Origin www.cnblogs.com/hehu/p/11565007.html