|
From: Per W. <pw...@ia...> - 2003-06-10 10:32:55
|
The compiler always zero-terminate strings if you just give it a chance.
char mystr[] = "foobar";
will store six characters and a termination. It's whey you try
char mystr[6] = "foobar";
that you might get into problems, since the array doesn't allocate space
for a termination. A lot of compilers will complain.
/Per W
On Mon, 9 Jun 2003, CARLSON, JAY MM1 wrote:
> Reply to printing - take 2 - This is a good way to print from a console. A
> file could be created a console program and then printed with a system()
> call. Below is a sample program that demonstrates how it works. It is
> longer than it has to be to show several variations at the same time.
>
> #include <iostream>
> #include <stdlib.h>
>
> using namespace std;
>
> int main(void) {
>
> // assuming c:\test.txt exits, this will work.
> // c:\test.txt should be a small file because it will print 4 times.
> // Notice the double backslash in the first non comment line
> // The backslash is a control characher so the first one
> // is stripped out before the command is executed.
> system("print c:\\test.txt");
> system("PRINT c:\\test.txt");
> system("print C:\\TEST.TXT");
>
> // Other ways to do the same thing.
> // This line could be dangerous - unterminated string
> const char* command01 = "Print C:\\test.txt"; /* do I need \0 ?
> */
> const char* command02 = "Print C:\\test.txt\0"; /* \0 ends the string
> */
> // This line could be dangerous - unterminated string
> const char command03[] = "Print C:\\test.txt"; /* do I need \0 ?
> */
> const char command04[] = "Print C:\\test.txt\0"; /* \0 ends the string
> */
>
> system(command01);
> system(command02);
> system(command03);
> system(command04);
>
>
> // all valid dos commands can by used by system()
> // you can get a list of commands by typing
> // HELP + [enter key] (if installed)
> //
> system("PAUSE");
> // notice case is not important to the system() call
> return 0;
> }
>
> Jay
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Etnus, makers of TotalView, The best
> thread debugger on the planet. Designed with thread debugging features
> you've never dreamed of, try TotalView 6 free at www.etnus.com.
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|