Professional Documents
Culture Documents
10
,
j
.
j C
FILE
stdio.h
j fopen j
(FILE*)
j
FILE * fopen ( const char * filename , const char * mode ) ;
filename - j j
mode -
| 10
2/22
r
w
a
r+
w+
a+
( )
(
)
(j )
(
j )
| 10
3/22
FILE * fp = fopen ( " C :\\ test . txt " , " r " ) ;
b j
. (rb)
j fclose
fclose ( fp ) ;
| 10
4/22
int fscanf ( FILE * fp , kontrolna niza , arguments_list )
int fgetc ( FILE * fp )
int fprtinf ( FILE * fp , kontrolna niza , arguments_list )
int fputc ( int c , FILE * fp )
| 10
5/22
a 1
1/2
j
.
j.
# include < stdio .h >
int is_letter ( char c ) {
return ( c >= a && c <= z ) || ( c >= A && c <= Z ) ;
}
int is_vowel ( char c ) {
c = tolower ( c ) ;
switch ( c ) {
case a :
case e :
case i :
case o :
case u :
return 1;
default :
return 0;
}
}
| 10
6/22
1
2/2
int main ( int argc , char * argv []) {
char c ;
int c ount_consonats = 0 , count_vowels = 0;
FILE * dat ;
// We need at least 2 arguments
if ( argc < 2) {
printf ( " Usage : % s \" file path \"\ n " , argv [0]) ;
return -1;
}
// Opening file
if (( dat = fopen ( argv [1] , " r " ) ) == NULL ) {
printf ( " The file % s cannot be open .\ n " , argv [1]) ;
return -1;
}
// Reading char by char until the EndOfFile ( EOF )
while (( c = fgetc ( dat ) ) != EOF ) {
if ( is_letter ( c ) ) {
if ( is_vowel ( c ) )
count_vowels ++;
else
count_consonats ++;
}
}
fclose ( dat ) ;
printf ( " Ratio vowel / consonats : % d /% d = %5.2 f \ n " , count_vowels ,
count_consonats ,
( float ) count_vowels / count_consonats ) ;
return 0;
}
| 10
7/22
a 2
j j
j
j j
.
j,
. j j 80
.
| 10
8/22
a 2
1/2
| 10
9/22
a 2
2/2
| 10
10/22
a 3
j
matrica1.txt.
j
. j
j .
matrica2.txt .
| 10
11/22
a 3
1/2
| 10
12/22
a 3
2/2
if ( i != m || j != n ) {
printf ( " Nema dovolno podatoci vo datotekata ! " ) ;
return ( -1) ;
}
for ( i = 0; i < m ; i ++)
for ( j = 0; j < n ; j ++)
b [ j ][ i ] = a [ i ][ j ];
if (( output = fopen ( " matrica2 . txt " , " w " ) ) == NULL ) {
printf ( " Datotekata matrica2 . txt ne se otvora !\ n " ) ;
exit (1) ;
}
fprintf ( output , " % d % d \ n " , n , m ) ; /* obratno */
for ( i = 0; i < n ; i ++)
for ( j = 0; j < m ; j ++)
fprintf ( output , " %7.2 f \ n " , b [ i ][ j ]) ;
fclose ( output ) ;
return (0) ;
}
| 10
13/22
a 4
KRSPrimer.txt.
j j
j , j
. j j 80 .
| 10
14/22
a 4
15/22
a 5
j
j
( j ).
. j
j .
.
20 .
j.
, , , , ,
| 10
16/22
a 5
1/2
| 10
17/22
a 5
2/2
| 10
18/22
a 6
j j
j
.
j.
j
, , Nevalidni
argumenti na komandna linija.
| 10
19/22
a 6
1/2
| 10
20/22
a 6
2/2
| 10
21/22
, , j
courses.finki.ukim.mk
https://github.com/tdelev/SP/tree/master/latex/src
j
forum.finki.ukim.mk
| 10
22/22