Cant print char value

Sorry, noob question, have searched the forum and not found what I think I need...

Reading a text file and simply want to print the char value read from the file, character by character... I can print it as an int, but can't read it and print, or even cast, it to a char value... can print the dec or hex rep of the character, not the character... why is "next" an int?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdlib.h>
#include <fstream>
#include <cstring>
using namespace std;

int main() {
	char next;		// character from file
	ifstream dataIn;	
	dataIn.open("data.txt");
	if (dataIn.fail())	
	{
		printf ("\nFailed to open data file\n\n");
		exit(1);
	}			
	while (! dataIn.eof())
	{
		dataIn.get(next);// read next char value ... why is it not a char???
		if (next != '\n') 
		{
			if (next != ' ') 
			{
			printf ("%s ", next);	// generates an error... not a char value
				// printf ("%d ", next);  
			}
		}		// end if not \n
	}			// end of while not eof
	dataIn.close();		// close file when done
}



Any and all help much appreciated.....

Last edited on
"%s" denotes that next should be a null terminated string.

"%c" is for char I believe that should be the only problem. ;)
Told you... noob question..

That was it, thanks much!
Everyone starts there ;)
Topic archived. No new replies allowed.