473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

string, char* and static char prob

hello NG,

i am trying to do some syscalls and therefore i need to put some text
together.
its no problem as long i want to cout the text to display, but when i
want to use it
as parameter for functions the variable only passes NULL....
the out commented code segments is my try to convert the static char*
to char* so i can work with this one, but it does not work either...
(compiles but app crashes then...)

i load the names from the list to memory, and i

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();

}

// checking if the list exists or not
bool listexists()
{
bool flag = false;
fstream filestr;
filestr.open("taxa.liste",ios::in);
if( filestr.is_open() )
{
flag=true;
}
filestr.close();
return flag;
}

Jul 9 '07 #1
1 2210
<lu******@gmail.comwrote in message
news:11*********************@r34g2000hsd.googlegro ups.com...
hello NG,

i am trying to do some syscalls and therefore i need to put some text
together.
its no problem as long i want to cout the text to display, but when i
want to use it
as parameter for functions the variable only passes NULL....
the out commented code segments is my try to convert the static char*
to char* so i can work with this one, but it does not work either...
(compiles but app crashes then...)

i load the names from the list to memory, and i

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();

}

// checking if the list exists or not
bool listexists()
{
bool flag = false;
fstream filestr;
filestr.open("taxa.liste",ios::in);
if( filestr.is_open() )
{
flag=true;
}
filestr.close();
return flag;
}
Since you are using C++ and not C, don't bother with sprintf_s. Just use
std::string.

Untested code:

while( getline(filestr, name) ) {
cout << name << '\n';

std::string call;
call = "php.exe getPopularName.php " + name;

cout << "[call]" << call << "[/call]\n";
system(call.c_str());
// system(const_cast<char*>( call.c_str() );
cout << ".";
counter++;
}

Note, logic of program wasn't looked at, just this funciton.

If a function is not const correct, sometimes you have to throw away the
const with const_cast. I think that most of windows calls are const
correct, however, so the const_cast won't be needed.

Jul 9 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
22
by: spike | last post by:
How do i reset a string? I just want to empty it som that it does not contain any characters Say it contains "hello world" at the time... I want it to contain "". Nothing that is.. Thanx
4
by: Prabhu | last post by:
Hi, We are having problem in converting a byte array to string, The byte array has char(174), char(175), char(240), char(242) and char(247) as delimiters for the message. when we use...
6
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards,...
2
by: PioM | last post by:
namespace System { public class Text { public static System.Char Omin='\t',Next=' ',Wciecie='\"',Zamkniecie='\"',Null='\0',Object='˙'; public static System.Int32 NextCharacter(System.Int32...
1
by: el jefe | last post by:
hey im new, howdy. here is my prob, i am have this problem using the string count function, i am trying to center some text. looking at my code will clarify. i will be forever in debt to whoever...
5
by: probstm | last post by:
I am using a message handler class that implements amongst others: static void message ( std::string aHeader, std::string aMessage, int aTimeout = 0, MessageType aFlag = MSG_Information ); ...
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
3
by: jacob navia | last post by:
Abstract: Continuing the discussion about abstract data types, in this discussion group, a string collection data type is presented, patterned after the collection in C# and similar languages...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.