I am writing a function that reads 10 .pgm files into a 2D array images
using ifstream
void readPGMImages ( unsigned char images [784][10], int img_size ,
const char * filename , int imgNum ){...
where the first dimension img_size
is the number of "pixels"(0-783) in the image and the second dim imgNum
is the image number(0-9). The place I am having trouble is that I am required to use const char* filename
to read in the new file title every time the image number changes. I just do not understand how to store the values of filename
properly or how to read in the names using const char*
.
void readPGMImages ( uchar images [784][10], int img_size ,
const char * filename , int imgNum ){
filename = "digit_00.pgm","digit_01.pgm","digit_02.pgm","digit_03.pgm","digit_04.pgm","digit_05.pgm","digit_06.pgm","digit_07.pgm","digit_08.pgm","digit_09.pgm";
int header;
ifstream PGM ;
PGM.open(filename);
for (imgNum = 0; imgNum<10; imgNum++){
PGM.open(filename);
PGM >> header >> header >> header >> header ; // this is b/c the first 4 characters of each are unused
for (img_size = 0; img_size<784 ; img_size++){
PGM >> images[img_size][imgNum];
}
const char* ++; // this is kind of pseudo code for what I am trying to accomplish
}
the names of the files are
filename = "digit_00.pgm","digit_01.pgm","digit_02.pgm","digit_03.pgm","digit_04.pgm","digit_05.pgm","digit_06.pgm","digit_07.pgm","digit_08.pgm","digit_09.pgm";
So in summary I have a pointer const char*
that points to filename
and I need const char* filename = digit_00.pgm
on the first iteration then I need filename = digit_01.pgm
on the second iteration and so on.
If I wasn't required to use const char*
I would make an array of strings and increment the string over the for loop but that is not what the problem I am tasked with solving is asking.
Thank you so much in advance! I will monitor the thread to clear up anything.