View previous topic :: View next topic |
Author |
Message |
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
Multi dimensional Arrays |
Posted: Fri Jul 24, 2015 12:25 pm |
|
|
Hi all,
Is it possible to do string operations on Multidimensional arrays?
say:
Code: | strcat(Array1, Array2[1][]); |
assume:
Code: | Array2[0][7]="abababa";
Array2[1][7]="cdcdcdc"; |
Something like that...
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Fri Jul 24, 2015 11:47 pm |
|
|
Yes, and no....
Yes. Perfectly possible.
No, not with what you show.
A _string_ in C, is an array of characters _with a terminating null_.
The string "abababa", is eight characters long, not seven. |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Sat Jul 25, 2015 7:40 am |
|
|
Hi,
I'm aware or the '\n' termination for strings...
I was just trying to convey my point quickly, not typing compilable pseudo.
I'm working on an IoT project which is working beautifully if i may say so, but id like to add more features by having a config.h file which holds the parts that change from one module to the other.
Rather than having a file with different GET/POST commands, i want to have a multidimensional array(string) and build the GETs on the fly...
It's a syntax question.... ive not seen on the manual how to feed <string.h> functions a multidimensional array.
Thanks.
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Sat Jul 25, 2015 11:36 am |
|
|
Not '\n'. The terminator on a string is '\0'.
You don't. The string functions accept a pointer to a string. Nothing else.
The address of the first element in each row, points to that row. The row is just a string.
I have to say 'get a C text book'. This is nothing special in CCS, it is how C handles this. The manual assumes you have a C book or some understanding of C.... |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sun Jul 26, 2015 6:50 am |
|
|
i think you can actually call a string operation on ANY location you set a pointer value to in memory, whether there is a string or not.
This is a strength and a weakness as CCS( and C in general )
has no bounds/dimension checking.
For all i know, you could even point to an SFR.
Just make sure there is a \0 terminator SOMEWHERE upstream before you pull the trigger |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Sun Jul 26, 2015 9:56 am |
|
|
... i was thinking "null" and typed '\n' because of the Letter N...
its a common mistake i make while programming.
anyways i came here for help, i guess its easier to be condescending. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
|