You are on page 1of 10

C

. , ,

:
, , 23
C
.

char :
char line[80]; // 80
line[i] = getchar(); //

+1 .

(#include <string.h>)
. , ,

O \0
( null character).
\0
0 (). O 0
( :00000000), 0
48 (00110000). :
printf(" %d, %d", '\0','0'); // : 0, 48

,
( " ) ( ' ). 'A' "A" :
'A' 1 byte (01000001)
"A" 2 bytes (A,\0 ==> 0100000100000000)
"A" 'A'
/0' .
. , ,

( )

:
char str1[6 ] = {'h', 'e','l','l','o','\0'};
( str1[0] h, t str1[1] e str1[5] \0 )

char str2[8] = "hello"; // '\0'


:
char str2[] = "hello"; //
: char str[20] = "hello"; 20
6.
\0 .
char str[20 ] = {'\0'}; '\0'
str.
H sizeof(str) .
. , ,

scanf(), gets()

scanf() %s:
printf ("What's your name :"); scanf(%s, str);
: & str
str 1 .
: scanf()
(space)
('\n').


gets():
printf("What's your name:"); gets(name);
H gets()
'\n' (
). '\n' '\0' .
. , ,

getchar()
int i;
char line[80];
i = 0;
// '\n'
while( (line[i]=getchar( )) != '\n' ) i++;
// '\0'
line[i]='\0';
printf("Diavasa %d xaraktires\n", i);

80;
//
while( (line[i++]=getchar( )) != '\n' );
line[i] = '\0';
. , ,

printf() %s:
printf(To onoma sou einai: %s\n", onoma);

printf()
'\0'.

printf()
:
printf(To onoma sou einai: %s\n", onoma+2);
( 3 )

puts():
printf("What's your name:"); gets(name);
printf("Hello "); puts(name);
puts() ,
'\n'.
. , ,

<string.h>

C
( o <string.h>.

.
:

strcpy(s1, s2); s2 s1.


strcat(s1, s2); s2 s1.
strlen(s1); ( ) s1.
strcmp(s1, s2); 0 s1 s2 .
0 s1<s2. 0 s1>s2.
strchr(s1, ch);
ch s1.
strstr(s1, s2);
s2 s1.
. , ,

<ctype.h>
. :
:
int isalnum(int c) -- True if c is alphanumeric.
int isalpha(int c) -- True if c is a letter.
int isascii(int c) -- True if c is ASCII .
int iscntrl(int c) -- True if c is a control character.
int isdigit(int c) -- True if c is a decimal digit
int isgraph(int c) -- True if c is a graphical character.
int islower(int c) -- True if c is a lowercase letter
int isprint(int c) -- True if c is a printable character
int ispunct (int c) -- True if c is a punctuation character.
int isspace(int c) -- True if c is a space character.
int isupper(int c) -- True if c is an uppercase letter.
int isxdigit(int c) -- True if c is a hexadecimal digit

:
int toascii(int c) -- Convert c to ASCII .
tolower(int c) -- Convert c to lowercase.
int toupper(int c) -- Convert c to uppercase.
. , ,


#include <stdio.h>
#include <string.h>
main () {
char str1[12] = "Hello";
char str2[12] = "World";
char str3[12];
int len ;
strcpy(str3, str1); /* str1 str3 */
printf("strcpy( str3, str1) : %s\n", str3 );
strcat( str1, str2); /* str1 str2 */
printf("strcat( str1, str2): %s\n", str1 );
len = strlen(str1); /* str1 */
printf("strlen(str1) : %d\n", len );
}
. , ,

10

You might also like