cout to printf

Hi how do i convert this code with cout to printf ?
thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
int n;
char * grid;
grid = (char*)malloc(n*n);

 for (int y = 0; y <  n; ++y)
	{
		for (int x = 0; x <n; ++x)
		{
			cout << grid[XYToIndex(x, y)];
		}
		cout << endl;
	}
	
To print a char with printf, you use the %c modifier. So your code might become something like this:

1
2
3
4
5
for(int x = 0; x < n; ++x)
{
    printf("%c",grid[XYToIndex(x, y)]);
}
printf("\n");


You should look up http://www.cplusplus.com/reference/cstdio/printf/ for a table with all format modifiers.
Topic archived. No new replies allowed.