Re: determining size of array of chars
- From: "Francesco S. Carta" <entuland@xxxxxxxxx>
- Date: Mon, 23 Aug 2010 17:10:33 +0200
dehantonio <dehantonio@xxxxxxxxx>, on 23/08/2010 08:00:02, wrote:
On 23 Ago, 16:51, You're talkin 'bout China Blue Grove
<chine.b...@xxxxxxxxx> wrote:
This is an array of strings, not chars. A trick to get the length of an array AIn other words, it will not work with my code. Correct?
is
(sizeof A/sizeof A[0])
provided A is actually an array and not a pointer.
Said that, the answer is there is no way to get rid of the define in
my code?
It seems to work - caveat, I'm just starting with C, so cope with any error of mine (but point them out if any, please):
#include <stdlib.h>
#include <string.h>
const char *LineMenu[] = {"ls", "pwd", "cd"};
int somefunction(char* inputbuffer) {
int idx;
const int menusize = sizeof(LineMenu) / sizeof(LineMenu[0]);
for (idx = 0; idx < menusize; idx++) {
if (strstr(inputbuffer, LineMenu[idx])) {
return idx;
}
}
//not found:
return -1;
}
int main(void) {
printf("%d\n", somefunction("cd"));
return 0;
}
--
FSC - http://userscripts.org/scripts/show/59948
http://fscode.altervista.org - http://sardinias.com
.
- Follow-Ups:
- Re: determining size of array of chars
- From: David Resnick
- Re: determining size of array of chars
- References:
- determining size of array of chars
- From: dehantonio
- Re: determining size of array of chars
- From: dehantonio
- determining size of array of chars
- Prev by Date: Re: determining size of array of chars
- Next by Date: Re: determining size of array of chars
- Previous by thread: Re: determining size of array of chars
- Next by thread: Re: determining size of array of chars
- Index(es):
Relevant Pages
|