i am using this function to read from a notepad file and fill the data in char str[255] but after I execute the function str is still empty.
char str[255]; char* data_pull() { std::ifstream in("C:/myfile.txt"); if(!in){ printf("\nCannot open the file"); exit (1); } while(in){ in.getline(str, 255); printf(str); } in.close(); return str; }
printf(str)? BTW, never useprintf(str)for str read from external input, since str might contain formatting code like "%s", better useputs(str)orprintf("%s", str). How do you see that the string returned is empty? Just a question aside: could it be that the last line in the text is an empty line?stris that empty line. Nothing strange here.