polska Posted May 14, 2012 at 10:48 PM Report #455617 Posted May 14, 2012 at 10:48 PM Boas pessoal, surgiume um erro ao compilar um programa no gcc que eu não estou a consseguir corrigir, o erro é o seguinte : exF.cpp: In function ‘int main()’: exF.cpp:13:23: error: ‘strtok’ was not declared in this scope Eu fui ver a linha, e tentei substituir a função strtok pela strtok_r ... Mas o erro manteve-se.. Vou deixar aqui o código: //EX F - TOPAS 2012 - ESDAH,BRUNO #include <stdio.h> #include <stdlib.h> #include <stdio.h> int main(){ int precoPretendido,cmp,nMoedas,v[6],i; char *pch,moedas[15]; scanf("%d",&precoPretendido); scanf("%d",&nMoedas); fgets(moedas,15,stdin); pch=strtok(moedas," "); i=0; while (pch!=NULL){ v[i]=atoi(pch); pch = strtok (NULL," "); i++; } do{ for(int j=0;j<nMoedas;j++){ // 4 for -> fazer comparações entre as moedas todas for(int k=j+1;k<nMoedas;k++){ for(int l=k+1;l<nMoedas;l++){ for(int n=l+1;n<nMoedas;n++){ cmp=v[j]+v[k]+v[l]+v[n]; if(cmp==precoPretendido){ printf("%d\n",precoPretendido); return 0; }else{ cmp=0; precoPretendido++; } } } } } }while(cmp!=precoPretendido); return 0; } Corrige um sábio e ele mais sábio ficará. Corrige um ignorante e um inimigo ganharás.
HappyHippyHippo Posted May 14, 2012 at 10:56 PM Report #455620 Posted May 14, 2012 at 10:56 PM faz include de <string.h> IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
polska Posted May 14, 2012 at 10:58 PM Author Report #455622 Posted May 14, 2012 at 10:58 PM faz include de <string.h> Ei que nabiço, eu pus duas vezes stdio em vez de string, ai que erro nabo 😄 Mais atençao.. xD, obrigado 👍 Corrige um sábio e ele mais sábio ficará. Corrige um ignorante e um inimigo ganharás.
pikax Posted May 15, 2012 at 10:13 AM Report #455674 Posted May 15, 2012 at 10:13 AM quando o erro for "error: ‘______’ was not declared in this scope" procura no google qual e' o include da funcao, a menos que seja uma funcao tua que esta noutro ficheiro. Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."
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