Subj : Re: Sending catenated cstring strings to the printer (Thank You) To : borland.public.cpp.borlandcpp From : "George Tamero" Date : Thu Mar 04 2004 07:52 pm Thank you very much! George maeder@glue.ch (Thomas Maeder [TeamB]) wrote: >"George Tamero" writes: > >> // write string to printer >> int Printer_Print(string inptString) >> { // write returns 0=success, 1=trouble >> char* whatToPrint=""; > >This variable definition is only accepted because of a deprecated implicit >conversion from 'array of 1 char const' to 'pointer to char' (non-const!). > >The reason why this is deprecated is that the array might very easily be >overwritten, which would cause the program to have undefined behavior. > > >> strcpy(whatToPrint, StringToArray(inptString)); > >And this is an example. If inptString.size() is !=0, your program has >undefined behavior. > > >> if(fputs(whatToPrint, file) != EOF) > >Better simplify the function to: > > if (fputs(inptString.c_str(),file)) > >> return 0; >> >> return 1; > >, or, better yet, the entire function to > > return fputs(whatToPrint,file) != EOF; .