int strncasecmp (const char *s1, const char *s2, size_t n)
int checkSchluessel(char* Aszkeys[], char* Zeile, int dim)
{
int i;
for (i=0; i<dim; i++)
if (strncasecmp(Zeile, Aszkeys[i])==0, [COLOR="Red"]LENGTH[/COLOR])
return i;
return _NOP;
}
for (i=0; i<dim; i++){
if (strncasecmp(Zeile, Aszkeys[i],[b]LENGTH[/b])==0){
return i;
}
}
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "math.h"
#define LENGTH 80
#define _NOP 99
int checkSchluessel(char* Aszkeys[], char* Zeile, int dim)
{
int i;
for (i=0; i<dim; i++)
if (strncasecmp(Zeile, Aszkeys[i], LENGTH)==0)
return i;
return _NOP;
}
int main(void)
{
typedef enum {EXIT, SET, ADD, SUB, MUL, DIV, NOP=_NOP} KEY;
char szTempstr[LENGTH];
char *AszSchluesselWoerter[] = {"exit", "set", "add", "sub", "mul", "div"};
int dim = 6, i=0;
KEY input = EXIT;
do
{
for (i = 0; i < LENGTH; i++)
szTempstr[i] = 0;
printf(">");
gets(szTempstr);
input = (KEY)checkSchluessel(AszSchluesselWoerter, szTempstr, dim);
switch(input)
{
case EXIT:
{
printf("Exit Program");
break;
}
case SET:
{
printf("SET erkannt");
break;
}
case ADD:
{
printf("ADD erkannt");
break;
}
case SUB:
{
printf("SUB erkannt");
break;
}
case MUL:
{
printf("MUL erkannt");
break;
}
case DIV:
{
printf("DIV erkannt");
break;
}
case NOP:
{
printf("Nichts erkannt!");
break;
}
}
printf("\n\n");
}
while(input != EXIT);
return 0;
}
<snip>
int checkSchluessel(char* Aszkeys[], char* Zeile, int dim)
{
int i;
for (i=0; i<dim; i++)
if (strncasecmp(Zeile, Aszkeys[i], strlen(Aszkeys[i])==0)
return i;
return _NOP;
}
<snip>
Code:<snip> int checkSchluessel(char* Aszkeys[], char* Zeile, int dim) { int i; for (i=0; i<dim; i++) if (strncasecmp(Zeile, Aszkeys[i], strlen(Aszkeys[i])==0) return i; return _NOP; } <snip>
Sorry, but I still don't really understand why I need "strlen(Aszkeys)==0" and not only some global number like "LENGTH".
The strcasecmp() and strncasecmp() return an integer greater than, equal
to, or less than 0, according as s1 is lexicographically greater than,
equal to, or less than s2 after translation of each corresponding charac-
ter to lower-case. The strings themselves are not modified. The compar-
ison is done using unsigned characters, so that `\200' is greater than
`\0'.
Thank you. But what I actually want to know is, why I need "strlen(Aszkeys)" and not only any number.