The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Passing String Variables to OC functions

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
bg-phys Posted - 08/10/2006 : 4:50:48 PM
Origin Version: 7.5 SR5
Operating System: Win XP SP2

I'd like to pass a string as an argument from a Labtalk script to an OC function. Is that possible? I've been getting an error with the following setup:

Inside a *.ogs file:

[LTCode]
type -b "Choose data file.";
getfile *.dat; //Stores filename to %A, file path (with trailing \) to %B
cFunction(%B%A);
type -a %A;



Inside a *.c file:


int cFunction(char * input)
{
printf("Input is %s\n\n",input);
return 0;
}



When I try to run by typing cFunction("Hello") in the script Window I get a Command Error.

When I try to run it by clicking a toolbar button that's set to run the [LTCode] section, I get no output to the Script Window.

In fact, I can't get output to the script window even if the OC Function is just a Hello World function and has no input parameters.

Is it possible to pass string variables to OC functions from LabTalk? If it isn't possible, how to I access the Labtalk string variables that I want the OC function to know about?

Is it possible to ensure that printf output from OC functions goes to the script window even when the OC function is started from a button that runs a labtalk script? (which in turn calls the OC function) If not, how do I view printf output from OC functions? (I still would like to call the function with a toolbar button.)


BG

P.S. I feel like some of my questions were a bit confusing. Please ask me to reword them if necessary.


3   L A T E S T    R E P L I E S    (Newest First)
cpyang Posted - 08/10/2006 : 6:35:52 PM
quote:
Does fopen(filename,"rb"); still work if filename is a string instead of a char*?


string class in Origin C is similar to MFC CString, so char* cast is automatic. So yes, you can put string into any function that expect LPCSTR or char*


CP


bg-phys Posted - 08/10/2006 : 5:49:13 PM
That works perfectly. All I had to do was change the input type from char* to string. Thanks for the quick reply.

Quick question though:

Does fopen(filename,"rb"); still work if filename is a string instead of a char*?


Edited by - bg-phys on 08/10/2006 5:54:08 PM
easwar Posted - 08/10/2006 : 5:00:29 PM
Hi BG,

Change your OC function to:
int cFunction(string input)
{
printf("Input is %s\n\n",input);
// or use out_str() function such as:
out_str(input);
return 0;
}

When calling the function from LT, note that if you have spaces in your string, you either need to protect using paranthesis or quote the string, such as:
cFunction(blah blah); // no quotes required in this case
cFunction "blah blah"

Also note that there are functions such as LT_get_str and LT_set_str that can be used to get and put strings between OC and LT.

As for making sure that the script window opens, you can issue the following statement in your LT script code:
type -a;
or you can issue that statemente from OC code if necessary using
LT_execute("type -a;");

Easwar
OriginLab



Edited by - easwar on 08/10/2006 5:03:20 PM

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000