By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,127 Members | 1,222 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,127 IT Pros & Developers. It's quick & easy.

system( char(26)) error

P: n/a
Hello
I have this line in my c++ code and it is giving the error below, not
sure why, I tried it on different boxes, same error. thanks

the last line in my main() I have this
system( (char(26));
error: invalid conversion from 'char' to 'const char*'
Jul 23 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Baloff wrote:
Hello
I have this line in my c++ code and it is giving the error below, not
sure why, I tried it on different boxes, same error. thanks

the last line in my main() I have this
system( (char(26));
error: invalid conversion from 'char' to 'const char*'


What's not to understand? The function system() wants a const char *,
but you passed it a single char. What are you trying to accomplish?

HTH,
--ag

--
Artie Gold -- Austin, Texas
http://it-matters.blogspot.com (new post 12/5)
http://www.cafepress.com/goldsays
*If it belongs to `it' it's `its'.*
Jul 23 '05 #2

P: n/a
Baloff wrote:
Hello
I have this line in my c++ code and it is giving the error below, not
sure why, I tried it on different boxes, same error. thanks

the last line in my main() I have this
system( (char(26));
error: invalid conversion from 'char' to 'const char*'


The error is quite clear. The footprint for system() is

int system(const char *);

You're passing a char to a function expecting a const char *.

Why are you trying to pass a ctrl-Z?

If you really want to do that, try:

system("\032");
Jul 23 '05 #3

P: n/a
Baloff wrote:
Hello
I have this line in my c++ code and it is giving the error below, not
sure why, I tried it on different boxes, same error. thanks

the last line in my main() I have this
system( (char(26));
error: invalid conversion from 'char' to 'const char*'


char(26) creates a temporary object of type char and initializes it with
the value 26. system() takes a const char * as an argument. Thus your
error. Without knowing what you were attempting to do nothing useful
can be said about how to fix your error.

More errors, your parentheses aren't correctly matched, and the last
line in main() should under most circumstances be a return statement.

Alan
Jul 23 '05 #4

P: n/a
Baloff wrote:
I have this line in my c++ code and it is giving the error below, not
sure why, I tried it on different boxes, same error. thanks

the last line in my main() I have this
system( (char(26));


What do you expect it do do? What made you think that syntax would do
anything?

What does the online help and tutorials tell you about system?

What does using Google or Google Groups tell you about system()?

What do the examples look like?

--
Phlip
http://www.c2.com/cgi/wiki?ZeekLand
Jul 23 '05 #5

P: n/a
Phlip wrote:
Baloff wrote:

I have this line in my c++ code and it is giving the error below, not
sure why, I tried it on different boxes, same error. thanks

the last line in my main() I have this
system( (char(26));

What do you expect it do do? What made you think that syntax would do
anything?

What does the online help and tutorials tell you about system?

What does using Google or Google Groups tell you about system()?

What do the examples look like?

I only took this code from Thinking in C++ Vol-1 and it did not compile
because of this error. I noticed this line "system(char(26))" in more
than one code in the few 3 chapters of the book. and since it is a book
with some good reputation, I did not think it would be incorrect. but it
looks I have to do some homework.

thanks
Jul 23 '05 #6

P: n/a
On 2005-07-21 20:17:43 -0400, Baloff <vd****@bi.edu.gr> said:
I only took this code from Thinking in C++ Vol-1 and it did not compile
because of this error. I noticed this line "system(char(26))" in more
than one code in the few 3 chapters of the book. and since it is a book
with some good reputation, I did not think it would be incorrect. but
it looks I have to do some homework.


Are you sure about that? I'm looking at the PDF version of the book
right now, and can't find that text anywhere. In fact, the only
reference to the system() function that I can find in any sample code
is on page 108:

//: C02:CallHello.cpp
// Call another program
#include <cstdlib> // Declare "system()"
using namespace std;

int main() {
system("Hello");
} ///:~

--
Clark S. Cox, III
cl*******@gmail.com

Jul 23 '05 #7

P: n/a
Clark S. Cox III wrote:
On 2005-07-21 20:17:43 -0400, Baloff <vd****@bi.edu.gr> said:
I only took this code from Thinking in C++ Vol-1 and it did not
compile because of this error. I noticed this line "system(char(26))"
in more than one code in the few 3 chapters of the book. and since it
is a book with some good reputation, I did not think it would be
incorrect. but it looks I have to do some homework.

Are you sure about that? I'm looking at the PDF version of the book
right now, and can't find that text anywhere. In fact, the only
reference to the system() function that I can find in any sample code is
on page 108:

//: C02:CallHello.cpp
// Call another program
#include <cstdlib> // Declare "system()"
using namespace std;

int main() {
system("Hello");
} ///:~

a while back I downloaded the book, I have now a directory with the
source codes, in the files for chapter 3, I could find these 2 programs.
//////////////////////////////////////////////////
//: C02:CallHello.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
// Call another program
#include <cstdlib> // Declare "system()"
#include <iostream>
using namespace std;

int main() {
system("date");
cin.sync(); cin.get(); return 0;
} ///:~
///////////////////////////////////////////////////
//: C03:Ifthen.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
// Demonstration of if and if-else conditionals
#include <iostream>
using namespace std;

int main() {
int i;
cout << "type a number and 'Enter'" << endl;
cin >> i;
if(i > 5)
cout << "It's greater than 5" << endl;
else
if(i < 5)
cout << "It's less than 5 " << endl;
else
cout << "It's equal to 5 " << endl;

cout << "type a number and 'Enter'" << endl;
cin >> i;
if(i < 10)
if(i > 5) // "if" is just another statement
cout << "5 < i < 10" << endl;
else
cout << "i <= 5" << endl;
else // Matches "if(i < 10)"
cout << "i >= 10" << endl;
system( char(26)); //<-- this line is not in the book but in the
source code bundled with the book according to the content of the file
in the folder, "assuming I did not modify it some time ago and forgot".
} ///:~
///////////////////////////////////////////////////////
Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.