Jump to content
  • Advertisement

Archived

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

Chronoslade

Gee.. I feel dumb

This topic is 6175 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
Advertisement
  
#include <stdio.h>

/* ... */

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

if(File == NULL) HandleError;

fseek(File,0,SEEK_END);
FileSize = ftell(File);
fseek(File,0,SEEK_SET);

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

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

fclose(File);

/* ... */


free(Data);


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

Share this post


Link to post
Share on other sites
your the best thank you, no access to anmy books today, or i would have found it myself


"There is humor in everything depending on which prespective you look from."

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!