Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Pessoal tenho q entregar esse trabalho pronto as 19 horas de hoje, sei q é sexta de carnaval mais tentem me ajudar por favor , no 3 arquivo onde eu salvo o vetor preciso q não seja salvo o lixo das posições q foram eliminas por serem repetidas
Tentei usar o cont da funcao q faz a junção mais não to conseguindo http://forum.imasters.com.br/public/style_emoticons/default/ermm.gif
Segue o codigo
/******************************************************************************/
/ Escrever funções que completam o programa abaixo: /
/******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
void Leitura_Arquivo_Inteiros(char argv, int vet, int qnt);//ler os arquivos
void Escreve_Arquivo_Inteiros(char argv, int vet, int qnt);//gravar em arquivo
void SelectionSort (int a[], int array_size); //ordenar o vetor
int Uniao_Vetores (int vetA, int qntA, int vetB, int qntB, int *vetC, int qntC);//unir 2 vet sem repetir os numeros
int main(int argc, char *argv[])
{
int qntA = 5, vetA[qntA];
int qntB = 10,vetB[qntB];
int qntC = 15,vetC[qntC];
if(argc < 4)
{
printf("\nErro: Digite o nomes dos arquivos !!!\n\n");
system("pause");
exit(1);
}
Leitura_Arquivo_Inteiros(argv[1],vetA,qntA);
system("pause");
system("cls");
Leitura_Arquivo_Inteiros(argv[2],vetB,qntB);
system("pause");
system("cls");
Uniao_Vetores(vetA,qntA,vetB,qntB,vetC,qntC);
Escreve_Arquivo_Inteiros(argv[3],vetC,qntC);
system("pause>>null");
return(0);
}
void Leitura_Arquivo_Inteiros(char argv, int vet, int qnt)
{
FILE *arquivo;
int lidos, j;
if ((arquivo = fopen(argv,"r")) == NULL)
{
printf("Erro ao abrir arquivo!!!\n\n");
system("pause");
exit(1);
}
lidos = 0;
while(fscanf(arquivo, "%d", &vet[lidos]) == 1)
{
lidos++;
}
fclose(arquivo);
printf("\nNumeros lidos : %2d\n",lidos);
printf("Os numeros sao:\n");
for(j=0; j<lidos; j++)
{
printf("%2d\n", vet[j]);
}
}
void Escreve_Arquivo_Inteiros(char arg, int numeros, int tam)
{
FILE *arquivo;
int i;
if((arquivo = fopen(arg,"w")) == NULL)
{
printf("Erro ao abrir arquivo!!!\n\n");
system("pause");
exit(1);
}
for (i=0; i<tam; i++)
{
fprintf(arquivo, "%d\n", numeros[i]);
}
fclose(arquivo);
printf("\n\t Dados gravados com sucesso em %s\n\n",arg);
}
int Uniao_Vetores(int vetA, int qntA, int vetB, int qntB, int *vetC, int qntC)
{
int i,j,c = 0;
int aux = 0;
int cont = 0;
for(i=0;i<qntA;i++)
{
vetC[c] = vetA[i];
c++;
cont++;
}
for(i = 0; i < qntB; i++ )
{
for( j = 0; j < qntA; j++)
{
if (vetB[i] != vetA[j])
aux = 1;
else
{
aux = 0;
break;
}
}
if (aux == 1)
{
vetC[c] = vetB[i];
c++;
cont++;
}
}
SelectionSort(vetC, qntC);
printf("\nVETOR CONCATENADO\n");
for(c=0;c<cont;c++)
{
printf("vetC[%2d] = %2d\n",c,vetC[c]);
}
system("pause");
system("cls");
printf("\n\n\t\t UNIAO REALIZADA COM SUCESSO!!!!\n\n");
}
void SelectionSort(int a[], int array_size)
{
int i;
for (i = 0; i < array_size - 1; ++i)
{
int j, min, temp;
min = i;
for (j = i+1; j < array_size; ++j)
{
if (a[j] < a[min])
min = j;
}
temp = a[i];
a[i] = a[min];
a[min] = temp;
}
}Carregando comentários...