D
David RF
Hi friends, here I am trying to avoid wchar_t in UTF8 strings.
glad to hear some critics
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
Return a new allocate string
Upper from (a - z) and (ÿþýüûúùø÷öõôóòñðïîíìëêéèçæåäãâáà)
-61 = first byte
-65 = ÿ
-96 = à
*/
char *stoupper(const char *s)
{
size_t len;
char *p = NULL;
int c = 0;
if (s) {
len = strlen(s);
p = malloc(len + 1);
if (p) {
while (*s) {
if ((*s >= 'a') && (*s <= 'z')) {
c = *p = *s - 'a' + 'A';
} else if ((c == -61) && ((*s <= -65) && (*s >= -96))) {
c = *p = *s - 32;
} else {
c = *p = *s;
}
p++;
s++;
}
*p = '\0';
p -= len;
}
}
return p;
}
int main(void)
{
char *s = "María tiene moño, Ramón tiene un camión.";
s = stoupper(s);
printf("%s\n", s);
return 0;
}
glad to hear some critics
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
Return a new allocate string
Upper from (a - z) and (ÿþýüûúùø÷öõôóòñðïîíìëêéèçæåäãâáà)
-61 = first byte
-65 = ÿ
-96 = à
*/
char *stoupper(const char *s)
{
size_t len;
char *p = NULL;
int c = 0;
if (s) {
len = strlen(s);
p = malloc(len + 1);
if (p) {
while (*s) {
if ((*s >= 'a') && (*s <= 'z')) {
c = *p = *s - 'a' + 'A';
} else if ((c == -61) && ((*s <= -65) && (*s >= -96))) {
c = *p = *s - 32;
} else {
c = *p = *s;
}
p++;
s++;
}
*p = '\0';
p -= len;
}
}
return p;
}
int main(void)
{
char *s = "María tiene moño, Ramón tiene un camión.";
s = stoupper(s);
printf("%s\n", s);
return 0;
}