Skip to main content
gamedev.net
🔒 Locked

file i/o

Started by Pillejunior 2 replies 650+ views
Original Post
Pillejunior
Pillejunior
This is my code that reads(anyway it should read) a binary file, but it keeps giving this error and i don''t know why. FILE *setupFile; // Used For Filling out window BYTE screenResolution; // Used To Set Screen Resolution BYTE bitsPerPixel; // Used To Set Color Depth BYTE soundSettings; // Used To Set Music & Sound BYTE OpenGL_DirectX; // Used To Set RederingDevice BYTE graphicsDetail; // Used To Set Texture Quality BYTE fileData[5]; // Array To Read Setupfile Data int checkFile; // Used To Check I/O //***Open file and read the data setupFile = fopen("c:/curtis/programeerstuff/curtisc++/setup/setup.bin", "r"); if(setupFile==NULL) { return -1; } else { if((checkFile = _read(setupFile,fileData,5)) <= 0) { return -1; } else { screenResolution = fileData[0]; bitsPerPixel = fileData[1]; soundSettings = fileData[2]; graphicsDetail = fileData[3]; OpenGL_DirectX = fileData[4]; } } fclose(setupFile); the error is this one: error C2664: ''_read'' : cannot convert parameter 1 from ''struct _iobuf *'' to ''int'' This conversion requires a reinterpret_cast, a C-style cast or function-style cast does someone know what i do wrong? Thanx in advance
VolkerG
VolkerG
Hi, the problem is that you are mixing the low level I/O function (_read) with the stream I/O routines (fopen and fclose). You should use fread (fileData, 5, 1, setupFile) instead of the _read function. That should work.
BeerNutts
BeerNutts
You also need to open the file with the "rb" parameter
ie.
fopen(FileHandle, "rb"); // opens it for reading binary
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.