Jump to content

Recommended Posts

Posted

Salutare tuturor. Nu-mi afiseaza in fisier nimica. Nu stiu unde am gresit.

#include<stdio.h>
#include<stdlib.h>
using namespace std;
long int n, s;
int main()
{
    FILE * f; FILE * g; f=fopen("numere.in","r"); g=fopen("numere.out","w");
    while(feof(f))
    {
        s+=n;
    }
    fclose(f);
    fclose(g);

    return 0;
}

Respecta si vei fi respectat.

Posted

while(feof(f)) asta nu cred ca e bun. ia uitate inca o data ce face functia aia, nar trebui sa fie o negare pe acolo? ia gandestete ce face feof ala mai exact.

 

insa sunt sigur ca nu ai afisat niciunde. ai deschis niste fisiere, dar nu citesti si nu scrii in niciunu. Cum scrii sau citesti in/din fisier?

love is a verb
Love is a doing word

Posted

Tot nu merge.

#include<stdio.h>
#include<stdlib.h>
using namespace std;
long int n, s=0;
int main()
{
    FILE * f; FILE * g; f=fopen("numere.in","r"); g=fopen("numere.out","w");
    while(fscanf(f,"%d",&n))
    {
        s+=n;
    }
    fprintf(g,"%d",s);
    fclose(f);
    fclose(g);

    return 0;
}

Respecta si vei fi respectat.

  • 1 month later...
Posted

#include<stdio.h>
#include<stdlib.h>
using namespace std;
 int n, s=0;
int main()
{
    FILE * f; FILE * g;
    f=fopen("numere.in","r");
    g=fopen("numere.out","w");

    while(fscanf(f,"%d",&n) == 1){  //daca citirea a reusit
        s+=n;
    }
    fprintf(g,"%d",s);
    fclose(f);
    fclose(g);

    return 0;
}

 

Userful:

http://www.cplusplus.com/reference/cstdio/fscanf/

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

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.