Pagini: [1]   În jos
  Imprimă  
Ajutor Subiect: freopen si EOF  (Citit de 3007 ori)
0 Utilizatori şi 2 Vizitatori pe acest subiect.
mingw
Strain


Karma: 5
Deconectat Deconectat

Mesaje: 2



Vezi Profilul
« : Martie 18, 2008, 13:24:38 »

Cum pot folosi functia freopen sa citesc din fisier pana cand se termina ?

exact ca si cu streamuri!

Cod:
while(citeste)
   {
executa
   }
Memorat
gabitzish1
Moderatori infoarena
Nu mai tace
*****

Karma: 321
Deconectat Deconectat

Mesaje: 926



Vezi Profilul
« Răspunde #1 : Martie 18, 2008, 13:33:22 »

Cod:
freopen("nume","r",stdin);

while (!feof(stdin))
{
       citeste;
       executa;
       etc..
}
Memorat
filipb
Nu mai tace
*****

Karma: 232
Deconectat Deconectat

Mesaje: 929



Vezi Profilul
« Răspunde #2 : Martie 18, 2008, 14:38:59 »

Cod:
freopen("a.txt", "r", stdin);
while (scanf("%d", &x) != EOF)
     printf("%d\n", x);
Memorat
toni2007
Nu mai tace
*****

Karma: 160
Deconectat Deconectat

Mesaje: 663



Vezi Profilul
« Răspunde #3 : Martie 18, 2008, 20:36:49 »

cu feof nu e bine Tongue  iti baga ultimu caracter de doua ori... e mai bine atunci cand ai siruri de caractere:

Cod:
while (gets(s)){
    faci ce vrei sa faci;
}

sau

cum a zis filip cristian buruiana cand tre citit numar
Memorat
rEbyTer
Vorbaret
****

Karma: -85
Deconectat Deconectat

Mesaje: 154



Vezi Profilul
« Răspunde #4 : Martie 18, 2008, 22:19:30 »

pentru caractere nu merge asa?
Cod:
freopen("a.txt", "r", stdin);
char x;
while (scanf("%c", &x) != EOF)
     printf("%d\n", x);
Memorat
flo_demon
Strain
*

Karma: 20
Deconectat Deconectat

Mesaje: 46



Vezi Profilul
« Răspunde #5 : Martie 18, 2008, 22:46:38 »

Si asa se poate. eu cel putin folosesc metoda asta.

Cod:
while (scanf(%c", &x) > 0)
    printf("%c", x);

http://www.cplusplus.com/reference/clibrary/cstdio/scanf.html

Citat
Return Value
On success, the function returns the number of items succesfully read. This count can match the expected number of readings or fewer, even zero, if a matching failure happens.
In the case of an input failure before any data could be successfully read, EOF is returned.
Memorat

Marines don't die! They go to hell and regroup
rEbyTer
Vorbaret
****

Karma: -85
Deconectat Deconectat

Mesaje: 154



Vezi Profilul
« Răspunde #6 : Martie 18, 2008, 22:48:33 »

cand atinge EOF returneaza -1 ?
Memorat
tvlad
De-al casei
***

Karma: 63
Deconectat Deconectat

Mesaje: 121



Vezi Profilul
« Răspunde #7 : Martie 18, 2008, 22:53:50 »

Da, returneaza constanta EOF care e -1
Memorat
wefgef
Nu mai tace
*****

Karma: 1049
Deconectat Deconectat

Mesaje: 3.008


razboinicu' luminii


Vezi Profilul
« Răspunde #8 : Martie 18, 2008, 23:21:53 »

Eu stiam ca valoarea EOF e machine dependent Smile.
Memorat

omului i-au fost date instinctele pentru a supravietui, nu pentru a fi sclavul lor.
Pagini: [1]   În sus
  Imprimă  
 
Schimbă forumul:  

Powered by SMF 1.1.19 | SMF © 2006-2013, Simple Machines