Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

285
Views
Convert a spanish string to uppercase

I want to convert a Spanish string to uppercase. I use the function toupper for all characters. The function does not convert characters with accent:

PROTECCIóN

Nor the enye character:

DAñO

I use the setlocale function.

setlocale(LC_ALL, "es_ES");
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It is possible to get the good result with setlocale(LC_ALL, "es_ES.utf8");, and use of wchar_t and of towupper(.) function.

Output

protección daño  PROTECCIÓN DAÑO

#include <stdio.h>
#include <stdlib.h>
#include <wctype.h>
#include <wchar.h>
#include <locale.h>

int main(void) {
    if (!setlocale(LC_ALL, "es_ES.utf8")) return 1;
    wchar_t input[] = L"protección daño";
    int length = sizeof(input)/sizeof(input[0]);
    wchar_t output[length];
    for (int i = 0; i < length-1; ++i) {
        output[i] = towupper(input[i]);
    }
    output[length-1] = '\0';
    printf ("%ls  %ls\n", input, output);
    
    return 0;
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!