c'de "file operation"sorunu :(

Mehmedean
30-03-2008, 12:03   |  #1  
OP Üye
Teşekkür Sayısı: 0
95 mesaj
Kayıt Tarihi:Kayıt: Ağu 2006

#include <stdio.h>
#include <stdlib.h>
#include <fstream.h>

struct game
{
        char name[30];
        char category[30];
        int year;
        int rating;
};

void main ()
{
        struct game temp;
        FILE *f;

        f = fopen("games.txt", "r+");

        fread(&temp, sizeof(struct game), 1, f);
        fwrite(&temp, sizeof(struct game), 1, f);
        fclose(f);
}
--------------------------------------------------------
Selam abiler. Ben yukaridaki koddaki hatayi bir proje yazarken karsilastim. Yukarda file'in 1. elemanini okuyup onu 2.'nin ustune basmak. Ama hicbirsey olmuyor!!! fread'den sonra fseek deyip 2'yi isaret ettirsem bile yazmiyor kerata!  Neden olabilir? games.txt'de kayitli 4 tane oyun var bu arada...

Son Düzenleme: Mehmedean ~ 30 Mart 2008 12:04
Mehmedean
30-03-2008, 12:16   |  #2  
OP Üye
Teşekkür Sayısı: 0
95 mesaj
Kayıt Tarihi:Kayıt: Ağu 2006

#include <stdio.h>
#include <stdlib.h>
#include <fstream.h>

fstream file;

class game
{
public:
        char name[30];
        char category[30];
        int year;
        int rating;
};

void main ()
{
        int index = 0;
        char choice = '\0', backspace='\0';
        game temp;

        file.open("games.txt", ios::in | ios::out);
        file.read((char *)&temp, sizeof(game));

        while (!file.eof())
        {
                if (temp.rating == -1)                // If an empty place found, then break!
                {
                        file.seekg(index * sizeof(game), ios::beg);
                        break;
                }

                file.read((char *)&temp, sizeof(game));
                index++;
        }

        printf("!%d!", index);
        file.seekp(sizeof(game), ios::beg);
        file.write((char *)&temp, sizeof(game));
        file.close();
}
--------------------------------------------------------
fstream kullansam bu seferde eof'u okudumu bir daha iflah olmuyor file pointer. ne seek ne write ne de read calisiyor! Hic boyle olmamisti yahu?