1) when i'm in the prompt and i call DELAY.exe i would like write the value on his right and then press ENTER.
In this situation i must call delay, press enter and then digit the value (and re-press enter)
2) i need get a line from a file (for this i used getline(ifstream&, string&)) but i need use a CHAR[] without A string type
2) I already answered that question and provided a link to the stream own version which takes a c-string (or null terminated character array, as it is called properly) as parameter.
But now i have anotherone problem..... i think i'm haveing a bad manage code... but i cannote found th problem:
//estract funz //take a piece of a string between a, b
char * estraistring(const char*riga, int a, int b){
int dimout=b-a+2;
char * out=new char[dimout];
1) You should store result of function somewhere to be able to delete it.
2) If your last line contains "-->" in expected place, following happens:
getline tries to extract a string from stream and either extracts no characters due to fact that stream contains no more characters. EOF is set here. original string is not changed.
estraistring is called. As riga was not changed, it operates on previous line which contains "-->" on expected place, and condition while (strcmp(estratto, "-->")){ evaluates to true, running loop once again ad infinum.
Some notes: do not loop on eof(). It is almost sure way to introduce bugs in your code. Best action is to loop on input operation.
Always check the successfulness of input operation before using it result. For example:
1 2 3
in.getline(riga, 200);
//You should check if getline was succesfull here before using riga on second line
estratto=estraistring(riga, 13, 15);
1) didn't i did it?
when i make a string and i assegn it on a pointer, deleting on pointer (delete[estratto]) the string 's space shoud be free.. or not??
2) i get it!! thanks!!
3) can you make me some examples on your suggesting?
"Some notes: do not loop on eof(). It is almost sure way to introduce bugs in your code. Best action is to loop on input operation."
4) infact i having problem about this
in.getline(riga, 200);
//You should check if getline was succesfull here before using riga on second line
estratto=estraistring(riga, 13, 15);
i don't know if is a funz(estraistring) problem that gave me a corrupt string (but i don't think) or if the operation getting faild (i didn't know it could be fail)
How can i check??? i don't know.... and WHY IT COULD NOT WORK?
I found the bug:
sometime when a RIGA was short and i asked its 13%15 position (that it hasn't) the stream (dirty) read --> of a maybe previously RIGA so it entered in "editime". I put a check on strlen.