Trinkes Posted May 31, 2013 at 05:03 PM Report #510307 Posted May 31, 2013 at 05:03 PM (edited) Alguem sabe se é possivel usar o fwrite desta forma? fwrite(("eu tenho %d anos", idade),(sizeof("eu tenho anos")+(sizeof(int)),1,f); Onde idade é um int. A minha duvida é se posso enviar a string daquela maneira(("eu tenho %d anos", idade)). Edited May 31, 2013 at 05:04 PM by Trinkes
HappyHippyHippo Posted May 31, 2013 at 05:07 PM Report #510312 Posted May 31, 2013 at 05:07 PM (edited) obviamente que não ... para não falar que tens p'rai umas contas que não fazem sentido o que necessitas de fazer é: char buffer[256]; sprintf(buffer, "eu tenho %d anos", idade); fwrite(buffer, strlen(buffer) + 1, 1, f); Edited May 31, 2013 at 05:07 PM by HappyHippyHippo IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
Trinkes Posted May 31, 2013 at 05:17 PM Author Report #510315 Posted May 31, 2013 at 05:17 PM (edited) obviamente que não ... para não falar que tens p'rai umas contas que não fazem sentido o que necessitas de fazer é: char buffer[256]; sprintf(buffer, "eu tenho %d anos", idade); fwrite(buffer, strlen(buffer) + 1, 1, f); Isso para ficheiros binários certo? Esquece...estava a pensar mal...então esse sprinf apenas mete tudo em string certo? Edited May 31, 2013 at 05:19 PM by Trinkes
HappyHippyHippo Posted May 31, 2013 at 05:55 PM Report #510320 Posted May 31, 2013 at 05:55 PM http://www.cplusplus.com/reference/cstdio/sprintf/ IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
Trinkes Posted May 31, 2013 at 06:02 PM Author Report #510321 Posted May 31, 2013 at 06:02 PM (edited) O problema é que eu tenho de guardar os valores como inteiros. Tenho de o fazer porque depois tenho de o ler como tal. Edited May 31, 2013 at 06:08 PM by Trinkes
HappyHippyHippo Posted May 31, 2013 at 06:10 PM Report #510324 Posted May 31, 2013 at 06:10 PM ?? o que estás p'rai a dizer ??? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
Trinkes Posted May 31, 2013 at 06:11 PM Author Report #510325 Posted May 31, 2013 at 06:11 PM ?? o que estás p'rai a dizer ??? Ao gravar no ficheiro como disseste vou faze-lo como string certo?eu preciso que os valores sejam guardados como inteiros.
HappyHippyHippo Posted May 31, 2013 at 06:17 PM Report #510328 Posted May 31, 2013 at 06:17 PM olha bem para o teu primeiro post : fwrite(("eu tenho %d anos", idade),(sizeof("eu tenho anos")+(sizeof(int)),1,f); qual é a razão de ter lá texto se queres a gravar em binário ? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
Trinkes Posted May 31, 2013 at 06:31 PM Author Report #510331 Posted May 31, 2013 at 06:31 PM 4 3 2 123 3 234 1 4 12 1 23 7 67 1 89 2 1 34 3 3 11 2 65 20 15 4 O que quero gravar é algo deste género...preciso dos espaços para poder separar os inteiros.
Rui Carlos Posted June 4, 2013 at 12:36 PM Report #510899 Posted June 4, 2013 at 12:36 PM Se queres guardar isso, por que é que estavas a colocar o eu tenho %d anos? E não, em binário não precisas de espaço para separar os inteiros. Basta-te saber o tamanho dos mesmos. Podes usar directamente o fwrite com os inteiros. Rui Carlos Gonçalves
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