Hi all I have been trying to display a txt file using pointer. heres the code, however Im only able to read first 20 character even though I set a while loop.
int main(){
ifstream infile;
char* p;
char buf[20];
infile.open("sample.txt");
note 1
It is possible that EOF is never hit if some other error occurrs to set either the failbit or badbit --in which case the eofbit will never be set and you'll have an infinite loop. Test instead against the failbit.
note 2
The getline() function guarantees to null-terminate buf, so just use p until *p is zero. Then you don't need <cstring> or extra calls to functions or signed-to-unsigned conversions, etc.