• Advertisement

Archived

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

Gee.. I feel dumb

This topic is 5998 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