systemcall with dynamic parameters from a textfile

L

lumo2000

hello ng!
i wrote a little application in php which searches along a webpage for
a latin animal name and returns me the "normal" name.

so all i need to do now is:
o - load a textfile and read the latin names from a textfile (one line
is one name of the animal)
o - make a systemcall and launch my application (which will
automatically create an file and appends the new latin name and the
normal translation.)

where is the problem?
well, i already loaded the names from the list to memory, and i
already am able to launch the application, but somehow i cant achieve
it to pass the parameters to the systemcall cause of char, constant
char and string problems (i am not too used to cpp and i wasnt able to
find a solution on google...)

the funny thing is i can output it to commandline (the correct system
call string...) but it does give me NULL when i try to put it
together :( - so i am out of ideas

so here is my code

#include "stdafx.h"
//#include "fstream.h"

bool listexists();
void getPopularNames();

int _tmain(int argc, _TCHAR* argv[])
{
if (listexists())
printf("taxa list file found!\n");
else
printf("error 404 - file [%S] not found\n");
getPopularNames();
// to get popular name call php file with latin name as parameter
// php.exe getPopularName.php "latin name"
return 0;
}

void getPopularNames()
{
ifstream filestr;
std::string name;
//char* name;
std::string res;
filestr.open("taxa.liste",ios::in);
int counter = 0;
cout << "processing";
if( filestr.is_open() )
{
while( getline(filestr, name) ) {
char call[1024];
cout << name << '\n';

//char *nonconstant_namecopy;
//nonconstant_namecopy = new char[name.length() + 1];
//strcpy_s(nonconstant_namecopy, name.length()+1, name.c_str());

sprintf_s(call, "php.exe getPopularName.php \"%S\"", name);
//cout << "<" << nonconstant_namecopy << ">";


//strcpy(call, name.c_str );
cout << "[call]" << call << "[/call]\n";
system(call);
// clean up
// delete [] nonconstant_namecopy;
cout << ".";
counter++;
}
}
cout << "finished processing " << counter << " latin names.";
filestr.close();
}

bool listexists()
{
bool flag = false;
fstream filestr;
filestr.open("taxa.liste",ios::in);
if( filestr.is_open() )
{
flag=true;
}
filestr.close();
return flag;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top