Ah well I fear the issue lies within my messy code rather than the strcmp method itself
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <String.h>
#include <stdbool.h>
#define ZEICHEN 1024
int inputcount = 0;
char code[ZEICHEN];
bool numeric = false;
bool alpha = false;
typedef const char* const CountryNameType;
typedef const unsigned int DialingCodeType;
struct country_code
{
CountryNameType country;
DialingCodeType code;
}
codes[] =
{
{"Austria" , 43},
{"Belgium", 32},
{"Cyprus", 357},
{"Czech Republic", 420},
{"Germany", 49},
{"Denmark", 45},
{"Estonia", 372},
{"France", 33},
{"Finland", 358},
};
int len = sizeof(codes)/sizeof(int)/2;
void statusCheck()
{
if (numeric && alpha)
{
printf("Unknown country name.\n");
return;
} else if (!numeric && alpha)
{
for (int i=0; i<len; i++)
{
if (strcmp(codes[i].country, code) == 0)
{
printf("Match: %d\n", codes[i].code);
return;
}
}
} else if (numeric && !alpha)
{
for (int i=0; i<len; i++)
{
if (codes[i].code == atoi(code))
{
printf("Match: %s\n", codes[i].country);
return;
}
}
}
}
void checkMethod()
{
numeric = false;
alpha = false;
inputcount = 0;
printf("Enter dialing code or country name: ");
while (1)
{
scanf("%c", &code[inputcount]);
if (code[inputcount] != '\n')
{
inputcount++;
if (isalpha(code[inputcount-1]))
{
alpha = true;
}
else if (isdigit(code[inputcount-1]))
{
numeric = true;
}
}
else
{
statusCheck();
checkMethod();
}
}
}
int main()
{
checkMethod();
return 0;
}