GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-Jul-2004, 16:37
mantako mantako is offline
New Member
 
Join Date: Jul 2004
Posts: 1
mantako is on a distinguished road

About variables in C


I'm just starting with C, and I'm wondering if C has a feature I love to use in PHP. In PHP, you can use what they call variable variables where you can dynamically use variables, like in this loop:

for($i; $i<$some_number; $i++)
{
$var{$i}='some string here';
}

So does C have something like this? Thanks in advance.
  #2  
Old 07-Jul-2004, 22:28
sho sho is offline
Junior Member
 
Join Date: Jun 2004
Posts: 49
sho will become famous soon enough
hello, actually c or c++ dont have the variable variable names feature...

you always have to create a variable name when you are coding, the program dont create it at runtime like that feature...

i was looking if that was possible too in a previous post but that feature isnt implemented...

but if you want that for something like in the example you show you can use an array and call it almost the same:

CPP / C++ / C Code:
for(int i=0; i<some_number; i++)
{
    var[i]="some string here";
}

hope this helps...
  #3  
Old 08-Jul-2004, 03:28
Garth Farley Garth Farley is offline
Invalid Email Address
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
No that's not quite the meaning in PHP. The curly brackets around the $i mean the value of $i is appended to the name $var. So it cycles over $var0, $var1, etc...

I know of no way of doing this in C++. It's a syntactic sugar of PHP.
GF
  #4  
Old 08-Jul-2004, 04:11
sho sho is offline
Junior Member
 
Join Date: Jun 2004
Posts: 49
sho will become famous soon enough
Quote:
Originally Posted by Garth Farley
No that's not quite the meaning in PHP. The curly brackets around the $i mean the value of $i is appended to the name $var. So it cycles over $var0, $var1, etc...

I know of no way of doing this in C++. It's a syntactic sugar of PHP.
GF
yeah i know... but looking at the sample code he added i told him that if he wanna made something like that (having variables with names var0, var1, var2, and so on) the most closer approach would be using an array with identifier var, so he would be using var[0], var[1], var[2] and so on...

but that only if he wanna make something like his sample code... because other useful implementations of variable variable names arent possible since c or c++ dont support them...
 
 

Recent GIDBlogToyota - 2008 September Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
passing variables out of an iframe by url JUNK KED MySQL / PHP Forum 5 31-Jul-2007 09:33
getting variables from $_GET & $_POST Dunc MySQL / PHP Forum 2 29-Mar-2004 05:45
Apache on Windows XP and passing variables Jos Elkink Apache Web Server Forum 4 21-Nov-2003 02:21
PHP variables nniehoff MySQL / PHP Forum 7 26-Jul-2002 06:25

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:44.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.