How could I print specific lines of a code in console?
The following codes print "Your Source Code as Output". And, I know that instead of the macro FILE, you enter the path of your file.
Let's say...I write a C/C++ code & wanna print from Line "x" to Line "y" or different lines of the same code in the output.
How could I achieve that?!
One final question:
Why in the C code is it printed this character <�> 'question mark inside diamond' at the end?
"Why it doesn’t show in C++ is a mystery to me though"
`std::string`, unlike C-string, is not a null-terminated object. As already pointed out, the `\0` character in a C-string object signals the end of the string because, in the implementation, there's no such thing as `str.length()` [it holds `content + '\0'`]. The '\0' is there to provide such effect, for example, when you call `strlen(str)` which reads the string until '\0' and returns the "visible length" of the string. The STL string container, however, holds `content + length` pretty much the same way that the `std::vector` does.
Note: Though, the traditional null-terminated buffer effect is achievable by a `c_str()` call.
Geovanny Martínez Forero
Diamond at the end in the output is the eof symbol. In the C version you are printing the eof symbol first and then checking if the char is indeed eof symbol and if yes you come out of do-while loop.
In C++ version you are first checking if the retrieved char is eof char before entering the loop, hence eof char is not printed. If you want to print correctly with do-while loop then you can do like this
char ch = getc(fp);
ch = getc(fp);
} while (ch != EOF);
C/C++ string discussion although correct has got nothing to do in the current context. There are no strings(C or C++) involved here. You are reading data char by char.