#Read a file and put the data in 3 tables
6 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
#include <stdio.h>
#define MAX_COUPS 100
void lecture (int coups[][2], int tab[2][1000][1000], int *taille, int *nbb, unsigned int *nombrea, unsigned int *nombreb) {
char input;
int a = 0;
scanf("%d %d", taille, nbb);
printf("taille: %d, nbb: %d\n", *taille, *nbb);
while (a == 0) {
scanf("%c", &input);
if (input == 'A') {
a++;
for (int i = 0; i < 1; i++) {
for (int j = 0; j < *taille; j++) {
for (int k = 0; k < *taille; k++) {
scanf(" %d%*c", &tab[i][j][k]);
if (tab[i][j][k] == 1) {
(*nombrea)++;
}
}
}
}
}
}
int test;
int b = 0;
while (b == 0) {
scanf("%c", &input);
if (input == 'B') {
b++;
for (int i = 1; i < 2; i++) {
for (int j = 0; j < *taille; j++) {
for (int k = 0; k < *taille; k++) {
scanf(" %d%*c", &tab[i][j][k]);
if (tab[i][j][k] == 1) {
(*nombreb)++;
}
}
}
}
}
}
int i = 0;
char c = 0, tt;
while (c == 0) {
scanf(" %c", &tt);
if (tt = 'A') {
for (int i = 1; i < 10; i++) {
scanf("%d%d", &coups[i][0], &coups[i][1]);
printf("%d %d", coups[i][0], coups[i][1]);
}
c++;
}
}
}
int main() {
int tab[2][1000][1000];
int coups[MAX_COUPS][2];
int taille, nbb;
unsigned int nombrea = 0, nombreb = 0;
lecture(coups,tab, &taille, &nbb, &nombrea, &nombreb);
printf("tableau1: \n");
for (int i = 0; i < 1; i++) // print le tableau
{
for (int j = 0; j < taille; j++) {
for (int k = 0; k < taille; k++) {
printf("%d ", tab[i][j][k]);
}
printf("\n");
}
printf("\n");
}
printf("tableau2: \n");
for (int i = 1; i < 2; i++) // print le tableau
{
for (int j = 0; j < taille; j++) {
for (int k = 0; k < taille; k++) {
printf("%d ", tab[i][j][k]);
}
printf("\n");
}
printf("\n");
}
printf("nombre de bateau dans tableau A: %d\n", nombrea);
printf("nombre de bateau dans tableau B: %d\n", nombreb);
}
P3.dat
10 6
*
A
0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
*
B
0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
*
A
*
7 5
7 7
2 6
8 3
7 3
2 6
5 5
8 7
9 6
8 2
2 7
7 0
7 2
7 7
9 4
1 1
8 7
5 8
1 3
6 3
-1
This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.