+ 14

How to redefine '[ ]' in C Language?

I tried to do that with #define. But I did not be able to achieve it. I googled it too. But I couldn't find something useful. Are there anybody who knows how to do that? I am planning to use it for a contest in Sololearn. For hash map: someArray["getInfo"] You can ask why are you not using C++ or C# or Python. Because I want to achieve it in C language, inshaAllah. If I will have time for this content. Thanks

26th Aug 2018, 12:26 PM
Yusuf
Yusuf - avatar
9 Réponses
+ 14
C does not appear to support operator overloading. Can you share your code? Perhaps we can figure an alternative way out?
26th Aug 2018, 12:51 PM
Hatsy Rei
Hatsy Rei - avatar
+ 5
I didn't write any line of code about hash table except '[ ]' things, because I don't want to waste my time if the result won't be natural. I just wondered that is it possible or not. Wherefore a lot of language written with C language, I do thought that there must be a way to do that. It means that the method that I thought for making a programming language is different than a real one. Thank you both for help.
26th Aug 2018, 4:01 PM
Yusuf
Yusuf - avatar
+ 5
Joseph Hardrock This is where you have to choose the right tool rather than rack your brain to come up with an extension for good old C which is already available by standard for its ++ version. Although C doesn't have this feature for user-defined data structures yet it designed to overload its built-in stuff like arithmetic operators and primitive types.
27th Aug 2018, 12:07 PM
Babak
Babak - avatar
+ 4
Joseph Hardrock I think you're trying to do operator overloading. This is an object oriented concept and can't be done in a non-object-oriented language like C. Raj Gajjar as // Zohir said you need to spell Console correctly for a start for your code to work.
27th Aug 2018, 12:24 AM
Sonic
Sonic - avatar
+ 3
Raj Gajjar Missing e to Consol.
26th Aug 2018, 9:20 PM
program
program - avatar
+ 1
array size can only be predefined in C language if the data remains constant throughout the program, as C language do not support dynamic coding in arrays as other languages. You can try the following method, if it doesn't work then please share the code. #define max 100 void main() { int array [max] : : }
27th Aug 2018, 2:13 PM
Subhojit Chatterjee
Subhojit Chatterjee - avatar
0
Struct?
27th Aug 2018, 1:33 PM
huseyin
huseyin - avatar
- 5
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { Consol.Writeline("HEY GUYS !"); } } } pleas tell me error
26th Aug 2018, 5:28 PM
Raj Gajjar
Raj Gajjar - avatar