Bonjour,

J'ai un petit soucis dans un programme (je débute). Dans le code, j'effectue 3 opérations
1) je rempli un tableau avec la valeur "1" => OK
2) je lis les valeurs du tableau => OK
3) je remplace ou j'additionne les valeurs => pas OK

Dans la 3ème opération , je veux réduire mon tableau qui fait 720 * 576 en 9 * 8 ... en gardant le même tableau (je ne veux pas faire un autre tableau, ni passer par un tableau intermédiaire)
Il me semble que le soucis se situe à la ligne :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
if ((ymodulobis >= 1)&&(xmodulobis >= 1))
: si une des 2 conditions est remplie, le programme passe au ELSE alors que je veux que les 2 conditions soient remplie

Le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
 
int main()
{
    int cols, rows, image[576][720];
    int y, x;
	int ybis, ymodulobis, xbis, xmodulobis;
	cols = 720;
	rows = 576;
 
	FILE* fichier = NULL;
	fichier = fopen("texte.txt", "w");
 
	for (y=0; y<rows; y++)
		{
		ybis = y / 71;
		ymodulobis = y % 71;
        for (x=0; x<cols; x++)
			{
			image[y][x] = 1;
			}
		}
 
    for (y=0; y<rows; y++)
		{
		ybis = y / 71;
		ymodulobis = y % 71;
        for (x=0; x<cols; x++)
			{
			xbis = x / 80;
			xmodulobis = x % 80;
			printf("x = %d y = %d gris = %d \n", x, y, image[y][x]);
				if ((ymodulobis >= 1)&&(xmodulobis >= 1))
				{
				image[ybis][xbis] += image[y][x];
				}
				else
				{
				image[ybis][xbis] = image[y][x];
				}
			fprintf(fichier, "x = %d %d %d y = %d %d %d gris = %d %d \n", x, xmodulobis, xbis, y, ymodulobis, ybis, image[y][x], image[ybis][xbis]);
			}
		}
	rows /= 71;
	cols /= 80;
fclose(fichier);
 
    return 0;
}
Le fichier
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
x = 0 0 0 y = 0 0 0 gris = 1 1 
x = 1 1 0 y = 0 0 0 gris = 1 1 
x = 2 2 0 y = 0 0 0 gris = 1 1 
x = 3 3 0 y = 0 0 0 gris = 1 1 
x = 4 4 0 y = 0 0 0 gris = 1 1 
x = 5 5 0 y = 0 0 0 gris = 1 1 
x = 6 6 0 y = 0 0 0 gris = 1 1 
x = 7 7 0 y = 0 0 0 gris = 1 1 
x = 8 8 0 y = 0 0 0 gris = 1 1 
x = 9 9 0 y = 0 0 0 gris = 1 1 
x = 10 10 0 y = 0 0 0 gris = 1 1 
x = 11 11 0 y = 0 0 0 gris = 1 1 
x = 12 12 0 y = 0 0 0 gris = 1 1 
x = 13 13 0 y = 0 0 0 gris = 1 1 
x = 14 14 0 y = 0 0 0 gris = 1 1 
x = 15 15 0 y = 0 0 0 gris = 1 1 
x = 16 16 0 y = 0 0 0 gris = 1 1 
x = 17 17 0 y = 0 0 0 gris = 1 1 
x = 18 18 0 y = 0 0 0 gris = 1 1 
x = 19 19 0 y = 0 0 0 gris = 1 1 
x = 20 20 0 y = 0 0 0 gris = 1 1 
x = 21 21 0 y = 0 0 0 gris = 1 1 
x = 22 22 0 y = 0 0 0 gris = 1 1 
x = 23 23 0 y = 0 0 0 gris = 1 1 
x = 24 24 0 y = 0 0 0 gris = 1 1 
x = 25 25 0 y = 0 0 0 gris = 1 1 
x = 26 26 0 y = 0 0 0 gris = 1 1 
x = 27 27 0 y = 0 0 0 gris = 1 1 
... 
x = 634 74 7 y = 575 7 8 gris = 1 75 
x = 635 75 7 y = 575 7 8 gris = 1 76 
x = 636 76 7 y = 575 7 8 gris = 1 77 
x = 637 77 7 y = 575 7 8 gris = 1 78 
x = 638 78 7 y = 575 7 8 gris = 1 79 
x = 639 79 7 y = 575 7 8 gris = 1 80 
x = 640 0 8 y = 575 7 8 gris = 1 1 
x = 641 1 8 y = 575 7 8 gris = 1 2 
x = 642 2 8 y = 575 7 8 gris = 1 3 
x = 643 3 8 y = 575 7 8 gris = 1 4 
x = 644 4 8 y = 575 7 8 gris = 1 5 
x = 645 5 8 y = 575 7 8 gris = 1 6 
x = 646 6 8 y = 575 7 8 gris = 1 7 
x = 647 7 8 y = 575 7 8 gris = 1 8 
x = 648 8 8 y = 575 7 8 gris = 1 9 
x = 649 9 8 y = 575 7 8 gris = 1 10 
x = 650 10 8 y = 575 7 8 gris = 1 11 
x = 651 11 8 y = 575 7 8 gris = 1 12 
x = 652 12 8 y = 575 7 8 gris = 1 13 
x = 653 13 8 y = 575 7 8 gris = 1 14 
x = 654 14 8 y = 575 7 8 gris = 1 15 
x = 655 15 8 y = 575 7 8 gris = 1 16 
x = 656 16 8 y = 575 7 8 gris = 1 17 
x = 657 17 8 y = 575 7 8 gris = 1 18 
x = 658 18 8 y = 575 7 8 gris = 1 19 
x = 659 19 8 y = 575 7 8 gris = 1 20 
x = 660 20 8 y = 575 7 8 gris = 1 21 
x = 661 21 8 y = 575 7 8 gris = 1 22 
x = 662 22 8 y = 575 7 8 gris = 1 23 
x = 663 23 8 y = 575 7 8 gris = 1 24 
x = 664 24 8 y = 575 7 8 gris = 1 25 
x = 665 25 8 y = 575 7 8 gris = 1 26 
x = 666 26 8 y = 575 7 8 gris = 1 27 
x = 667 27 8 y = 575 7 8 gris = 1 28 
x = 668 28 8 y = 575 7 8 gris = 1 29 
x = 669 29 8 y = 575 7 8 gris = 1 30 
x = 670 30 8 y = 575 7 8 gris = 1 31 
x = 671 31 8 y = 575 7 8 gris = 1 32 
x = 672 32 8 y = 575 7 8 gris = 1 33 
x = 673 33 8 y = 575 7 8 gris = 1 34 
x = 674 34 8 y = 575 7 8 gris = 1 35 
x = 675 35 8 y = 575 7 8 gris = 1 36 
x = 676 36 8 y = 575 7 8 gris = 1 37 
x = 677 37 8 y = 575 7 8 gris = 1 38 
x = 678 38 8 y = 575 7 8 gris = 1 39 
x = 679 39 8 y = 575 7 8 gris = 1 40 
x = 680 40 8 y = 575 7 8 gris = 1 41 
x = 681 41 8 y = 575 7 8 gris = 1 42 
x = 682 42 8 y = 575 7 8 gris = 1 43 
x = 683 43 8 y = 575 7 8 gris = 1 44 
x = 684 44 8 y = 575 7 8 gris = 1 45 
x = 685 45 8 y = 575 7 8 gris = 1 46 
x = 686 46 8 y = 575 7 8 gris = 1 47 
x = 687 47 8 y = 575 7 8 gris = 1 48 
x = 688 48 8 y = 575 7 8 gris = 1 49 
x = 689 49 8 y = 575 7 8 gris = 1 50 
x = 690 50 8 y = 575 7 8 gris = 1 51 
x = 691 51 8 y = 575 7 8 gris = 1 52 
x = 692 52 8 y = 575 7 8 gris = 1 53 
x = 693 53 8 y = 575 7 8 gris = 1 54 
x = 694 54 8 y = 575 7 8 gris = 1 55 
x = 695 55 8 y = 575 7 8 gris = 1 56 
x = 696 56 8 y = 575 7 8 gris = 1 57 
x = 697 57 8 y = 575 7 8 gris = 1 58 
x = 698 58 8 y = 575 7 8 gris = 1 59 
x = 699 59 8 y = 575 7 8 gris = 1 60 
x = 700 60 8 y = 575 7 8 gris = 1 61 
x = 701 61 8 y = 575 7 8 gris = 1 62 
x = 702 62 8 y = 575 7 8 gris = 1 63 
x = 703 63 8 y = 575 7 8 gris = 1 64 
x = 704 64 8 y = 575 7 8 gris = 1 65 
x = 705 65 8 y = 575 7 8 gris = 1 66 
x = 706 66 8 y = 575 7 8 gris = 1 67 
x = 707 67 8 y = 575 7 8 gris = 1 68 
x = 708 68 8 y = 575 7 8 gris = 1 69 
x = 709 69 8 y = 575 7 8 gris = 1 70 
x = 710 70 8 y = 575 7 8 gris = 1 71 
x = 711 71 8 y = 575 7 8 gris = 1 72 
x = 712 72 8 y = 575 7 8 gris = 1 73 
x = 713 73 8 y = 575 7 8 gris = 1 74 
x = 714 74 8 y = 575 7 8 gris = 1 75 
x = 715 75 8 y = 575 7 8 gris = 1 76 
x = 716 76 8 y = 575 7 8 gris = 1 77 
x = 717 77 8 y = 575 7 8 gris = 1 78 
x = 718 78 8 y = 575 7 8 gris = 1 79 
x = 719 79 8 y = 575 7 8 gris = 1 80