Jump to content

Problemas com arrays duplos


Upper
 Share

Recommended Posts

Boas tenho o seguinte codigo

void ler_palavras (int num, char chave[][MAX_WORD_LENGTH], char colocar[][MAX_WORD_LENGTH]) {
    int i=0,j=0, ind, k;
    while(i <= num)
    { 
      printf("%d palavra a substituir: ", (num+1));
      while(gets(chave[][MAX_WORD_LENGHT)!=1){
         printf("Erro na leitura\n");
         printf("%d palavra a substituir: ", (num+1));}
      printf("%d palavra a colocar: ", (num+1));
      while(gets(colocar[][MAX_WORD_LENGTH])!=1){
         printf("Erro na leitura\n");
         printf("%d palavra a colocar: ", (num+1));}
       i++;
    }
}

Quando compilo aparece.me erro nos dois ultimos whiles...alguem me pode dizer o que devo fazer?

Link to comment
Share on other sites

Não estás a indicar a posição do array onde é suposto colocares o valor lido. Adicionalmente, chave[][MAX_WORD_LENGHT] é do tipo char, quando a função gets está à espera de um array, ou seja, devias ter chave[...] apenas.

Por último, usa a função fgets em vez da gets, e para a próxima coloca aqui o erro que obtinhas, pois pode ser útil para saber qual o problema.

Link to comment
Share on other sites

void ler_palavras (int num, char chave[][MAX_WORD_LENGTH], char colocar[][MAX_WORD_LENGTH]) {
    int i=0,j=0, ind, k;
    while(i <= num)
    { 
      printf("%d palavra a substituir: ", (num+1));
      while(gets(chave[][MAX_WORD_LENGHT)!=1){
         printf("Erro na leitura\n");
         printf("%d palavra a substituir: ", (num+1));}
      printf("%d palavra a colocar: ", (num+1));
      while(gets(colocar[][MAX_WORD_LENGTH])!=1){
         printf("Erro na leitura\n");
         printf("%d palavra a colocar: ", (num+1));}
       i++;
    }
}

Ja corrigi o codigo, mas tenho que usar gets. Os erros sao falta algo antes dos pareteses rectos a fechar tanto do colocar como do chave e erro antes do primeiro fechar {

Link to comment
Share on other sites

void ler_palavras (int num, char chave[][MAX_WORD_LENGTH], char colocar[][MAX_WORD_LENGTH]) {
   int i=0,j=0;
   for(i=0; i <= num; i++)
   { 
      printf("%d palavra a substituir: ", (num+1));
      while(gets(chave[])!=1){
         printf("Erro na leitura\n");
         printf("%d palavra a substituir: ", (num+1));}
   
     printf("%d palavra a colocar: ", (num+1));
      while(gets(colocar[])!=1){
         printf("Erro na leitura\n");
         printf("%d palavra a colocar: ", (num+1));}
    }
}

Este e que e o codigo

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.