Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C (http://www.programmingforums.org/forum60.html)
-   -   code in variable (http://www.programmingforums.org/showthread.php?t=12536)

fightthecool Feb 8th, 2007 6:56 PM

code in variable
 
would it work if i put a code in a string and then just placed the string by itself like this:

:

thisisastring = printf("hello world");

thisisastring;


yeah i know the coding is bad but im in a lil bit of a hurry cuz im leaving in a few minutes so i didnt have the time to write something but would that work?

if not does any one have an alternative method of doing something like this?

DaWei Feb 8th, 2007 7:01 PM

Nope. I'd say more, but I'm in a bit of a hurry.

fightthecool Feb 8th, 2007 7:10 PM

lol alright ill explain a lil more seen as i just saved myself a bit of time and i notice sum sarcasm in the air but what i want to do is allow the user to type in a code and have the computer run it

like say the user inputted:

:

printf("hello, how are you?");

could i have the code saved and run later so that the program actually outputs "hello, how are you?" on the screen

Eoin Feb 8th, 2007 7:14 PM

Sounds like you'd want to save the code to a file entered and later compile the file with a compiler.

fightthecool Feb 8th, 2007 7:31 PM

Quote:

you'd want to save the code to a file entered and later compile the file with a compiler.
oh alright i was afraid of that

Arevos Feb 8th, 2007 8:13 PM

This sounds like a job for an embedded scripting language like Lua. Here's a quick tutorial on how to embed Lua in C.

Fall Back Son Feb 8th, 2007 10:52 PM

It wouldn't work the way you tried to make it work. I didn't know you could do this, but if you have a code which saves thisisastring as a printf statement, and then you use another printf statement and print out the variable thisisastring - it will print out hello world followed by a few integers. not sure why, maybe someone else can explain.

bl00dninja Feb 9th, 2007 3:34 AM

so..............

you want a user to enter data, then you will send it to stdout at a later time?

what are you trying to do?

you could cin>>some stuff

then sleep() for awhile, then cout<<their bullshit;

this sounds weird. please say exactly what you're trying to do.

Jimbo Feb 9th, 2007 4:36 AM

It sounds like the OP is trying to write an interpreter. That would work for an interpreted language but it would be perhaps less than trivial to do for compiled languages.

jim mcnamara Feb 9th, 2007 4:34 PM

Or he's trying to write shellcode....


All times are GMT -5. The time now is 1:50 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC