Re: passing a filename to main()
- From: "Mickael Drean" <mickael drean gmail com>
- To: "Leandro Fanzone" <leandro hasar com>
- Cc: gtkmm-list gnome org
- Subject: Re: passing a filename to main()
- Date: Mon, 6 Mar 2006 17:30:22 +0100
Oups, in fact it was too simple :
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
CApp App;
if (argc > 1)
{
Glib::ustring tracename;
tracename = argv[1];
}
Gtk::Main::run(App);
return 0;
}
2006/3/6, Leandro Fanzone <leandro hasar com>:
You can't copy a string without asigning space to it. So either you:
char *inpname = argv[1];
printf(inpname);
or
printf(argv[1]);
Otherwise you'll get a coredump. If you really want a copy of the
string:
char *inpname = new char[strlen(argv[1])+1];
strcpy(inpname,argv[1]);
printf(inpname);
but as you're in C++, you can use STL strings:
#include<string>
...
std::string inpname(argv[1]);
printf(inpname.c_str());
Note that you should use printf("%s", inpname), or std::cout <<
inpname.
Mickael Drean wrote:
Hi there,
I tried to specify a file to load to my application on startup but it
didn't works. At that moment I tried to only show the name of the file
specified.
Here is my code :
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
if (argc > 1)
{
char* inpname;
strcpy(inpname,argv[1]);
printf(inpname);
}
CMyApp App;
Gtk::Main::run(App);
return 0;
}
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]