Upper Posted November 29, 2009 at 09:40 PM Report Share #298024 Posted November 29, 2009 at 09:40 PM 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 More sharing options...
Rui Carlos Posted November 29, 2009 at 10:24 PM Report Share #298028 Posted November 29, 2009 at 10:24 PM 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. Rui Carlos Gonçalves Link to comment Share on other sites More sharing options...
Upper Posted November 30, 2009 at 11:25 AM Author Report Share #298065 Posted November 30, 2009 at 11:25 AM 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 More sharing options...
Upper Posted November 30, 2009 at 11:26 AM Author Report Share #298066 Posted November 30, 2009 at 11:26 AM 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 More sharing options...
Rui Carlos Posted November 30, 2009 at 09:35 PM Report Share #298124 Posted November 30, 2009 at 09:35 PM Já indiquei o problema anteriormente. Não estás a indicar a posição do array onde é suposto colocares o valor lido. Coloca chave[0] ou chave[ i], por exemplo (tens que ver qual o valor que deves colocar em função do teu objectivo). Rui Carlos Gonçalves Link to comment Share on other sites More sharing options...
Upper Posted November 30, 2009 at 09:38 PM Author Report Share #298126 Posted November 30, 2009 at 09:38 PM Mas chave e uma string Link to comment Share on other sites More sharing options...
Baderous Posted November 30, 2009 at 10:13 PM Report Share #298142 Posted November 30, 2009 at 10:13 PM chave -> apontador para apontador de caracter (mais facilmente - matriz) chave[a] -> string chave[a][c] -> caracter A função gets guarda o conteúdo lido numa string, logo... Link to comment Share on other sites More sharing options...
Upper Posted November 30, 2009 at 10:19 PM Author Report Share #298146 Posted November 30, 2009 at 10:19 PM mas chave[a][c] nao pode ser uma string em que o c e a coluna? Link to comment Share on other sites More sharing options...
Baderous Posted November 30, 2009 at 10:24 PM Report Share #298148 Posted November 30, 2009 at 10:24 PM Eu acabei de te dizer que não. chave[a][c] é o caracter que está na linha 'a', coluna 'c'. Link to comment Share on other sites More sharing options...
Upper Posted November 30, 2009 at 10:28 PM Author Report Share #298151 Posted November 30, 2009 at 10:28 PM E que quem me deu este enunciado disse que char chave[MAX_WORD][MAX_WORD_LENGTH]; em k o primeiro[] e coluna e deve ser sempre tratado como 0(neste caso so pode existir um espaço) o segundo [] e o comprimento do texto por isso e que perguntei Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now