.
cprintf | CONIO.H | |
fprintf | STDIO.H | |
printf | STDIO.H | stdout |
sprintf | STDIO.H |
.
cscanf | CONIO.H | |
fscanf | STDIO.H | |
scanf | STDIO.H | stdin |
sscanf | STDIO.H |
. .
ß
char buf[100];
FILE *F;
F = fopen("111.txt", "w");
for (;;) {
gets(buf);
if (strlen(buf) > 40)
break;
fputs(buf, F);
fputs("\n", F);
}
fclose(F);
. gets stdin. '\n' .
fgets(buf, 100, F), fputs("\n", F) .
. . .
ß
char buf[100], maxbuf[100];
FILE *F;
maxbuf[0] = 0;
F = fopen("111.txt", "r");
while (!feof(F)) {
fgets(buf, 100, F);
if (strlen(buf) > strlen(maxbuf))
strcpy(maxbuf, buf);
}
fclose(F);
fputs(maxbuf, stdout);
. stdout
puts(maxbuf);
. .
ß
int buf;
FILE *F;
F = fopen("111.dat", "w");
for (;;) {
scanf("%d", &buf);
if (!buf)
break;
fwrite(&buf, sizeof(int), 1, F);
}
fclose(F);
. (scanf fscanf.).
fread.
3.4
1. -?
2. ?
3. , ?
4. ?
5. fopen?
6. ?
7. ?
8. , ?
9. , ?
10. , ?
11. , ?
12. ?
13. printf fprintf?
14. fscanf?
15. fscanf?
. .
|
|
. , , .
3.6
1
. :
1) , ;
2) , .
2
. , .
. , .
3
. :
1) , ;
2) , .
4
. :
1) , ;
2) , .
5
. :
1) , ;
2) , .
6
. :
1) , ;
2) .
7
8 8 k, k- k- .
, .
8
. , .
, .
9
- i-1 i+1, j-1 j+1, (, ) (i, j). , . 10 10. , .
10
, . 10 10.
, .
11
. .
, .
|
|
12
, , . , .
13
( ), .
14
MxN k : 1- , , , ; .
15
. , .
. , .
16
.
, .
17
, , (2,2), (3,3) . ., .
, .
18
. :
1) , ;
2) , .
19
. :
1) , ;
2) , .
20
. :
1) , ;
2) .
/*
,
.
"f2.txt" "f3.txt",
.
"f2.txt".
.
"f1.txt"
3 4
5 4 7 4
-8 9 -9 -3
4 -5 6 5
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("%s","Nachalo program\n");
FILE *fin(NULL),*fout(NULL);
char namef[40];
puts("Vvedite imja file\n");
gets(namef);//
fin=fopen(namef,"r");//
if (!fin)
{
printf("Can not open file\n");
return 1;
}
fout=fopen("f2.txt","w");//
int n,m;// n m
fscanf(fin,"%d%d",&n,&m);//
int **mas=new int*[n];
int i,a;
for(i=0;i<n;i++)
mas[i]=new int[m];
//
for(i=0;i<n;i++)
for(int j=0;j<m;j++)
fscanf(fin,"%d",&mas[i][j]);
//
|
|
for(i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
printf("%5d",mas[i][j]);// 5
}
printf("%c",'\n');
}
fclose(fin);
//
for(i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
fprintf(fout,"%5d",mas[i][j]);// 5
}
fprintf(fout,"%c",'\n');
}
fclose(fout);
//
for(i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
fprintf(fout,"%5d",mas[i][j]);// 5
}
fprintf(fout,"%c",'\n');
}
fout=fopen("f3.txt","wb");//
//
for(i=0;i<n;i++)
{
fwrite(mas[i],sizeof(int)*m,1, fout);
}
fclose(fout);
int **mas2=new int*[n];
for(i=0;i<n;i++)
{
mas2[i]=new int[m];
}
fin=fopen("f3.txt","rb");//
//
for(i=0;i<n;i++)
{
fread(mas2[i],sizeof(int)*m,1, fin);
}
printf("%c",'\n');
//
//
for(i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
printf("%5d",mas2[i][j]);// 5
}
printf("%c",'\n');
}
fclose(fout);
//
int otr(0);
for(i=0;i<n;i++)
for(int j=0;j<m;j++)
if(mas[i][j]<0) otr++;
fout=fopen("f2.txt","a+");
printf("%s%d","\nkoli4estvo otricat elementov= ",otr);
fprintf(fout,"%s%d","\nkoli4estvo otricat elementov= ",otr);
puts("\nKonec\n");
getchar();
return 0;
}
//---------------------------------------------------------------------------
/*
"f2.txt"
5 4 7 4
-8 9 -9 -3
4 -5 6 5
koli4estvo otricat elementov= 4
*/
4
4.2
C++ , . , . . , C++, :
?::: # # sizeof
(-) :
- , ( ), ;
- ;
- - ;
- - ( =);
- - static.
- operator, :
operator ( ) { }
:
struct Tstud
{
char FIO[20];
int bal;
};
struct TAB
{
float A;
int B;
};