windows and files, why can't we get along?

Started by
10 comments, last by Malchivus 20 years, 6 months ago
i can''t get the functions to read file to work in visual c++ 6.0 on winXP. i treid the olde open() read() ones but those didn''t work. i tried _lread(wint openfile and lopen) and fread() and even fscanf() then casting characters into data(this was the only way i could write files btw) so now i''m trying to read the files and i can''t get them open without the program falling apart. i doubt the source would help if i posted it here because i''m copying it out of that cool c book by kerigan/ritchie. ie the sameples should work. i''m woried that this problem is realted to the NTFS or FAT32 systems and microsoft never developing bug free implementations of ANSI C file reading functions. i am currently at a university that doesn''t believe in dorm network or phone conections being useful for everyone (hey their british!) but i haven''t found a lab with diskdrives so i''m probaly going to want to copy it all to a notebook and take it back to my room. i''m using this for all file acess (levels animations, sound? dialouge, configuration) so i''m not anxious to use d3d texture loading methods, not that i know how, if i did i would. I just wanna get this done.
I just wanna get this done.
Advertisement
I doubt that the problem is in your Compiler / OS, else I am sure that someone else would have posted about this before.

I''d guess it is in your code, but without seeing anything, I can''t really help.
#include <stdio.h>
#include <stdlib.h>

int main ()
{

FILE *file = NULL;
char data[500];

file = fopen("c:\\directory\\file.txt","rb");
fread(&data, 500, 1, file);
fclose(file);
file = NULL;

return 0;
}


notice the double ''\'' in the fopen() function !!!

- Iliak -
- Iliak -
[ ArcEngine: An open source .Net gaming framework ]
[ Dungeon Eye: An open source remake of Eye of the Beholder II ]
quote:Original post by iliak
char data[500];

file = fopen("c:\\directory\\file.txt","rb");
fread(&data, 500, 1, file);

- Iliak -


What you want is the address of data[0]

data is a pointer to the address of data[0]...
data == &data[0]

so what you want is either:
fread(data, 500, 1, file);
OR
fread(&data[0], 500, 1, file);



What is Barrel Drop?
Who are HTS Games?
after fopen() when i check the returnded value i get an error expresing that i have tried to allocate too much memory, the number it says is 4 less than 4gb(the limit for a 32 bit memory system) so my guess is that the function is trying to allocate an int or word and subtracting the number of bytes it needs from zero, this causes an overflow which causes this . . . but the code does look like that. is this something related to precompiled heades? i realy have no clue whats going on here

I just wanna get this done.
I just wanna get this done.
quote:Original post by Malchivus
after fopen() when i check the returnded value i get an error expresing that i have tried to allocate too much memory


excuse my french, but WTF?

fopen() returns a FILE HANDLE which you''ll use to actually read the file, with fread() (and yeah, close it with fclose() afterwards...)

post your code or learn to code.

i'm gona go buy disketes so i can post it. all i need to show is the functions that use it right? so like:

function that calls the fileacess

fileacess i'm using

i like help, i apoligize if i'm making it to complex for anyone to help.

I just wanna get this done.

[edited by - malchivus on October 17, 2003 11:32:52 AM]
I just wanna get this done.
heres the code for my functions, i have put macros around them because i was changing how they worked so often it didn''t make sense not to.

void LoadAnimation(char *Fname, CAnimation Var)
{
INFILE_TYPE InFile;

//open a file for input
OPEN_INFILE_TYPE(InFile,Fname);

if (INFILE_BAD(InFile))
{
LastErr = "Couldn''t open the passed animation file";
return false;
}

//read the number of animations
ACESS_INFILE(InFile,&(Var->m_iAnimationsInTotal),sizeof(int));

//write the number of frames
ACESS_INFILE(InFile,&(Var->m_iFramesInTotal),sizeof(int));

//there will be more but right now not even this much works
}

//i used macros because it was easier to swap back and fourth between functions with them
typedef int INFILE_TYPE;

#define CLOSE_INFILE_TYPE(FILE_VAR) close(FILE_VAR)
#define OPEN_INFILE_TYPE(FILE_VAR,STR) FILE_VAR = open(STR,O_RDWR,0)
#define INFILE_BAD(FILE_VAR) false(FILE_VAR == -1)
#define ACESS_INFILE(FILE_VAR,MEM,SIZE) read(FILE_VAR,MEM,SIZE)


typedef FILE *INFILE_TYPE;

#define CLOSE_INFILE_TYPE(FILE_VAR) fclose(FILE_VAR)
#define OPEN_INFILE_TYPE(FILE_VAR,STR) FILE_VAR = fopen(STR,"rb")
#define INFILE_BAD(FILE_VAR) (FILE_VAR == NULL)
#define ACESS_INFILE(FILE_VAR,MEM,SIZE) fread(MEM,1,SIZE,FILE_VAR)
//#define ACESS_INFILE(FILE_VAR,MEM,SIZE) SketchWinFileReadHack(FILE_VAR,MEM,SIZE)

//and just in case you want this . . . i had to wrie the files ina simmilar way
void SketchWinFileReadHack(FILE *Source, void *Data, unsigned int Size)
{
unsigned char *buff;
unsigned int pozish;

buff = (unsigned char *) Data;


pozish = 0;
while (pozish < Size)
{
buff[pozish] = fgetc(Source);
pozish ++;
}
}

I just wanna get this done.
I just wanna get this done.
that thing CAnimation is actualy a pointer. the items refrenced or whatever are both ints. the message board seems to have erased all my neat tabs

I just wanna get this done.
I just wanna get this done.
oh is there anyway to get rid of that "balh blah blah were microsoft. you are using a learning edition" box that hapens when i start my programs? it makes it impossible to write any dlls that don''t seem to mess up directX

I just wanna get this done.
I just wanna get this done.

This topic is closed to new replies.

Advertisement