5 Replies - 1102 Views - Last Post: 05 March 2010 - 04:46 PM Rate Topic: -----

#1 Guest_KoryMiller*


Reputation:

A program to open a .iff file

Posted 05 March 2010 - 03:02 PM

I have reading online tutorials about file IO in c++ and I understand the concept when it comes to opening text files. I have learned how to open them and edit them. However, I have a file that is a .iff extension (the file contains hex values only) and I would like to write a simple program to open that type of file and change the hex values around. Is there a way to open a proprietary file type like this in c++ ??


Thanks!
Is This A Good Question/Topic? 0

Replies To: A program to open a .iff file

#2 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 614
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: A program to open a .iff file

Posted 05 March 2010 - 03:28 PM

The file contains hexadecimal values? Is their anyway you can post this file to make things more clear?

You can open files in binary mode to get the actual raw values from the file (ie the ones the CPU see's as machine code), or do you mean that this file contains literal hexadecimal values. For example

0x10 0x2 0x38 0x0A

edit: basically, you can open a file to view the ASCII representation of the contents (like opening with notepad) or you can open in binary mode to see the machine code. Which are you looking for?

This post has been edited by Aphex19: 05 March 2010 - 03:30 PM

Was This Post Helpful? 1
  • +
  • -

#3 KoryMiller  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 07-February 10

Re: A program to open a .iff file

Posted 05 March 2010 - 03:59 PM

The file contains literal hex values. The file is here http://sandbox-games.com/roster.7z

Basically the file is a roster for a baseball game and all the player's value for name, position etc are hex values 0x11CB etc etc.

What I would like to do is to open this file with my program and be able to edit those values to change names etc etc

This post has been edited by KoryMiller: 05 March 2010 - 04:08 PM

Was This Post Helpful? 0
  • +
  • -

#4 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 614
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: A program to open a .iff file

Posted 05 March 2010 - 04:26 PM

View PostKoryMiller, on 05 March 2010 - 02:59 PM, said:

The file contains literal hex values. The file is here http://sandbox-games.com/roster.7z

Basically the file is a roster for a baseball game and all the player's value for name, position etc are hex values 0x11CB etc etc.

What I would like to do is to open this file with my program and be able to edit those values to change names etc etc


After viewing the file, Im assuming you are opening the file with a hex editor (hence, viewing the hex notation of the values). When i open it, it looks like the file is actually compiled in some way. When I open it in notepad++ I just get garbage, which is basically the ASCII representation of the values in the file. I assume you want to open it in the same way a hex editor does (amiright?)

To do that, I've wrote a little program for you that gives an example, assuming that the file is in the same directory as the program (called roster.iff)

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

int main()
{
	// File path
	const char *filePath = "roster.iff";
	long fileSize;	// Size of file

	FILE *file = NULL;				// Pointer to the file 
	file = fopen(filePath, "rb");	// Open file in binary mode

	// Does the file exist?
	if (filePath == NULL)
	{
		printf("File doesn't exist");
		return false;
	}

	// Get size of file
	long lCurPos, lEndPos;
	lCurPos = ftell(file);
	fseek(file, 0, 2);
	lEndPos = ftell(file);
	fseek(file, lCurPos, 0);
	fileSize = lEndPos;

	// Allocate space for the file in a buffer
	unsigned char *buffer = (unsigned char *)malloc(fileSize);

	// Read entire file into buffer
	fread(buffer, fileSize, 1, file);		
	
	// print some of the file out
	for (int i = 0; i < 10; i++)
		printf("%d:%X\n", i, buffer[i]);

	std::cin.get();
	free(buffer);
	return 0;

}


this program prints the first 10 values in the file in hex as if you were opening it with a hex editor. Maybe this may help you?

This post has been edited by Aphex19: 05 March 2010 - 04:44 PM

Was This Post Helpful? 1
  • +
  • -

#5 KoryMiller  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 07-February 10

Re: A program to open a .iff file

Posted 05 March 2010 - 04:39 PM

That helps a ton!

Thank you!
Was This Post Helpful? 0
  • +
  • -

#6 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 614
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: A program to open a .iff file

Posted 05 March 2010 - 04:46 PM

View PostKoryMiller, on 05 March 2010 - 03:39 PM, said:

That helps a ton!

Thank you!


Your welcome. ^_^

I had a hard time learning how to open files like this due to people not explaining it simply, so It's nice to help others and make it a little easier.

This post has been edited by Aphex19: 05 March 2010 - 05:07 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1