Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Gee.. I feel dumb

This topic is 6083 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

It''s early today.... Can anybody tell me how to open a text file in C or C++ and read it into an array that contains numbers, letters, and characters. I need this so i can scan text doc one element at a time. Any help would be appreciated. "There is humor in everything depending on which prespective you look from."

Share this post

Link to post
Share on other sites
#include <stdio.h>

/* ... */

unsigned char *Data;
long FileSize;
FILE *File = fopen("File.txt","rb");

if(File == NULL) HandleError;

FileSize = ftell(File);

Data = (unsigned char *) malloc(FileSize);
if(Data == NULL) HandleError;

if(fread(Data,1,FileSize,File) != FileSize) HandleError;


/* ... */


[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!