C++: No output for Char* when on AIX. Worked on Linux


 
Thread Tools Search this Thread
Top Forums Programming C++: No output for Char* when on AIX. Worked on Linux
# 8  
Old 12-06-2010
Quote:
Originally Posted by Leedor
I tried changing the signature to
Code:
char *CrncyFmt (const char* CharIn, const char* CharDecPrecNum)

but then compilation failed:
Code:
"CrncyFmt.cpp", line 63.24: 1540-0258 (S) A return value of type "char *" cannot be initialized with an expression of type "const char *".

It means what it says it means. You're trying to return a const char * as a char *.

I have no idea what you're doing now, but whatever it is, you shouldn't be doing that. Are you at least returning a static local buffer yet?
This User Gave Thanks to Corona688 For This Post:
# 9  
Old 12-06-2010
Just take the orginal and change the return statement at the end to this:

Code:
return( ::strdup( StrOut.c_str() ) );

Just make sure you call ::free() on the returned pointer. Not delete - ::free().

Passing in a buffer means you have to deal with the off chance of getting a string longer than you buffer - you can't ignore that.
This User Gave Thanks to achenle For This Post:
# 10  
Old 12-07-2010
Corona, thanks for your reply and help, unfortunately my almost non-existent C++ knowledge means I'm sure I've misunderstood you and am not doing it right.

Achenle: I tried your solution and it seems to work fine. Have not yet been able to test from within Datastage yet, but thanks very much for you help!
# 11  
Old 12-08-2010
Quote:
Originally Posted by Leedor
Corona, thanks for your reply and help, unfortunately my almost non-existent C++ knowledge means I'm sure I've misunderstood you and am not doing it right.
Don't apologize, I don't expect you to know everything. But I can't correct your code if I can't see it from here either! You have to post it! Smilie
Quote:
Achenle: I tried your solution and it seems to work fine. Have not yet been able to test from within Datastage yet, but thanks very much for you help!
Will Datastage be able to free() the resulting memory after? if not, your application will leak memory. I suspect it would not, hence why I was suggesting static local variables instead.
# 12  
Old 12-08-2010
Hi Corona,

Thanks again for getting back to me. My final code is as achenle suggested: as per my original attachment with that single change. This seems to work fine and I have checked the Datastage forums and verified that it handles memory allocation to ensure no leaks.

Cheers,

Lee
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Calculating Total Hours worked

Write a script using a Linux shell programming language to perform clock management for a small daycare. The program should manage all time in and out routines. At the end of the each day should give the Total hours worked that day. Example: Time-In 6:30am Lunch-Out 11 :25am... (1 Reply)
Discussion started by: sarapham409
1 Replies

2. UNIX for Beginners Questions & Answers

Sleep command did not worked

Hi All, We have a process which is running for last 2 years well and good in production. But suddenly yesterday there was issue we faced in the process. The actual process is what it does like below. 1. Receive the files in NAS directory(N/w attached storage). 2. Trigger the... (11 Replies)
Discussion started by: mad man
11 Replies

3. UNIX for Dummies Questions & Answers

Code not worked,as expected

Hi All, OS :- HPUX.. I have a following code, which I wrote to meet date and time condition. The below code refuse to work for some reason, I still don't have any idea, why ? the below code, should exit out, if the day happens to be sat and time greater the 04:00 pm. I am bit surprised, that... (2 Replies)
Discussion started by: alok.behria
2 Replies

4. Programming

error: invalid conversion from ‘const char*’ to ‘char*’

Compiling xpp (The X Printing Panel) on SL6 (RHEL6 essentially): xpp.cxx: In constructor ‘printFiles::printFiles(int, char**, int&)’: xpp.cxx:200: error: invalid conversion from ‘const char*’ to ‘char*’ The same error with all c++ constructors - gcc 4.4.4. If anyone can throw any light on... (8 Replies)
Discussion started by: GSO
8 Replies

5. Solaris

Anyone worked with ldmp2v?

Hi, has anyone worked with ldmp2v utility to convert a physical machine to a virtual. I am been trying to convert an ultra 45 (test machine) to an ldom on a T6320 blade server (with ldom manager 1.3) but have been unsuccessful. The firmware of the blade has been upgrade to the latest available.... (0 Replies)
Discussion started by: Mack1982
0 Replies

6. Shell Programming and Scripting

Different output in AIX and Linux OS

Hi All , Please help me in understanding why i am getting error for the below script in LINUX, but the same script will work perfectly in AIX unix. Script Name:try.ksh #!/bin/ksh echo "$0 \n" MYPWD=$(pwd $(dirname $0)) echo " $MYPWD \n" O/P in LINUX OS: ./try.ksh ./try.ksh:... (2 Replies)
Discussion started by: sudhir_barker
2 Replies

7. Shell Programming and Scripting

vi command -output garbage char in HP-UX

Hi all , I am new to HP-UX flavour of unix. i am issuing simple "vi" comand on the command prompt it is showing me some garbage character in command prompt itself ..unreadable format. I tried opening an existing file using the vi editor --and same thing ... (3 Replies)
Discussion started by: jambesh
3 Replies

8. Shell Programming and Scripting

test to see if useradd worked

I am trying to write a script that does a useradd -G <group> <user> but you cannot modify the user if he/she is logged on. How could I check to see if the user is on or if the user has been added to the group successfully? I plan on having the script sleep for a couple mins if the user is on then... (3 Replies)
Discussion started by: doublejz
3 Replies

9. UNIX for Dummies Questions & Answers

Variables being worked on inside of loops

I have a while read loop that reads values inside of a file and then performs an expr operation on each. Everything works fine, the way it's supposed to but, once the loop is finished, I can not access the variable that I used inside of the loop (but that variable was created outside of the... (7 Replies)
Discussion started by: yongho
7 Replies
Login or Register to Ask a Question