exculdeing items from fgetc

Hey all,

Yesterday I received some great help with a problem reading in some info because it had a character ('\n') that needed to be excluded from the read in.

The lines of code that worked was

1
2
3
4
5
6
7
8
9
10
11
12
13
	do 
	{
		if ((data = fgetc(gol_grid_file)) != '\n')
		{

				Grid[rowcount][columncount] = data - '0';

				if (++columncount == GRID_COLUMNS && ++rowcount < GRID_ROWS)
					columncount = 0;

		}
		
	} while (rowcount < GRID_ROWS && columncount < GRID_COLUMNS);


I would like to know one of two things.

Is there a similar way to specify two items to be excluded? Can the statement be modified to exclude '\n' and '\r'? I tried doing a nested "if" but that caused a double read.

Is there a way to specify only certain characters to be read in? As I am only interested in reading the '1' and '0' could that be specified and everything else omitted?
Last edited on
I figured it out.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
	do 
	{
		if ((data = fgetc(gol_grid_file)) != '\n')
		{
			if (data != '\r')
			{
				Grid[rowcount][columncount] = data - '0';

				if (++columncount == GRID_COLUMNS && ++rowcount < GRID_ROWS)
					columncount = 0;
			}
		}
		
	} while (rowcount < GRID_ROWS && columncount < GRID_COLUMNS);
Topic archived. No new replies allowed.