第二次第二次将无法正常工作

时间:2019-12-23 18:26:17

标签: c

很抱歉打扰你们,但是我有一个问题。第二次(当i = 1时),第二个for循环将不起作用,并且将被忽略。我已经有一段时间这个问题了。如果有人解决了我的问题,我将不胜感激(对不起,我的英语有点生锈)。

.c

void listar_clientes(CLIENT client[])
{

int j=0,i=0;
HISTORIC historic[100];
ler_Destinys(historic);
ler_clientes(client);
printf("----------------------------------------------------------------------\n\t\t\tClients:\n"); /**just for style that printf*/



for(i=0;i<num_client;i++)
{
    printf("\tCliente %d:\n\t\tNome: %s %s\n\t\t\n",cliente[i].id,cliente[i].nome,cliente[i].sobrenome);
    for(j=0;j<num_destiny;j++)
    {

        if(client[i].histor->binary[j]>0)/**the second time this will not work and its ignore*/
        {
            printf("already visited:");
            printf( "%s",historic[j].nome);
        }

    }

}
printf("------------------------------------------------------------------------\n");

} 

int ler_clientes(CLIENTE cliente[]) {                                                                                  
int i=0,j=0;
FILE *fp;
fp = fopen("Client.txt","r");
int num_client;
if( fp == NULL ) {
    printf("\nError!\n");
}
else
{
    fscanf(fp , "%d\n" , &num_client);
    for(i=0;i<num_client;i++)
    {
        fscanf(fp , "%d" , &client[i].id);
        fscanf(fp , "%s" , client[i].nome);
        fscanf(fp , "%s " , client[i].sobrenome);
        for(j=0;j<4;j++)
        {
            fscanf(fp,"%d ",&cliente->histor[i].binary[j])
        }
    }

}
fclose(fp);
return 0;
 } 

“ ler_Client”用于读取txt文件,因此我可以用于listar(用于写人民的名字和他们去过的地方

void ler_Destiny(HISTORIC histo[])
{
int i = 0;
FILE *fp;
fp = fopen("Destiny.txt", "r");
if (fp == NULL)
{
    printf("\nERROR\n");
}
else
{
    for (; i < 4; i++)
    {
        fscanf(fp , "%d" , &histo[i].id);
        fscanf(fp , "%s" , histo[i].nome);
    }
    fclose(fp);
}
}
void  ler_Destiny(HISTORIC histo[])
{
int i = 0;
FILE *fp;
fp = fopen("Destiny.txt", "r");
if (fp == NULL) {
    printf("\nERROR\n");
}
else {
    for (; i < 4; i++) {
        fscanf(fp , "%d" , &histo[i].id);
        fscanf(fp , "%s" , histo[i].nome);
    }
    fclose(fp);
}
}

ler_Destiny正在读取Destiny文件中的是非题,这将告诉他们是否访问过该地点。

void  ler_Destiny(HISTORIC histo[]) {
int i = 0;
FILE *fp;
fp = fopen("Destiny.txt", "r");
if (fp == NULL) {
    printf("\nERROR\n");
}
else {
    for (; i < 4; i++) {
        fscanf(fp , "%d" , &histo[i].id);
        fscanf(fp , "%s" , histo[i].nome);
    }
    fclose(fp);
}
}

.h

typedef struct histo 
{
int binario[TAM_S], id;
char nome[TAM_M];
} HISTORIC;

typedef struct cliente 
{
char nome[TAM_M], sobrenome[TAM_M];
int id;
HISTORICO histor[TAM_S];
} CLIENTE;

如果需要文件在这里

Destiny.txt
1 Porto
2 Lisboa
3 Aveiro
4 Alentejo
Clients.txt
5
1 Manuel Monteiro 0 1 0 1
2 Maria Fernandes 0 1 0 1
3 Ines Cornio 0 1 0 1
4 Fernanda Guimaraes 0 0 0 0
5 Fernanda Guimaraes 1 1 1 1`

0 个答案:

没有答案