1
#include <stdio.h>


int main(int argc, const char * argv[]){
   
    for (char i='A'; i<='Z'; i++){
        printf(" %c ",i);
        if (i=='N')
            printf("%c",165);
    }
    
    return 0;
}
Dai
  • 141,631
  • 28
  • 261
  • 374
  • I've seen that code 165 is settled for the character 'Ñ' according to ASCII, so I do not understand why it appears /245 instead – Saúl Arias Sep 01 '21 at 04:37
  • 3
    ASCII only provides codes up to 127. What you've seen is a chart for a coding someone called ["extended ASCII"](https://en.wikipedia.org/wiki/Extended_ASCII), which is a highly ambiguous and somewhat misleading description for an encoding which is now completely obsolete. – rici Sep 01 '21 at 04:42
  • Why aren't you using UTF-8? – Dai Sep 01 '21 at 04:53
  • 1
    Welcome to Stack Overflow. Please read https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/ , and strongly consider using any language other than C or C++ for heavy text manipulation. – Karl Knechtel Sep 01 '21 at 04:56
  • Thank you so much for your help, I'm new into programming and teacher and most of my classmates use devc++ so thats why they ask for these ASCII codes – Saúl Arias Sep 01 '21 at 04:59

1 Answers1

1

In order to print/use the character Ñ is a program, you need to be using a character set that supports it. The easiest is probably if your system supports unicode (which most do these days), which would allow you to do something as simple as

printf("\u00d1");

which will print the unicode character codepoint #00D1, which is Ñ

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226
  • 1
    `printf` should only be used with format-strings. Use `puts` to render a string value otherwise you potentially open yourself up to vulnerabilities: https://stackoverflow.com/questions/46776664/exploiting-printf-vulnerability-in-c and https://owasp.org/www-community/attacks/Format_string_attack – Dai Sep 01 '21 at 04:54
  • You are incorrect. It is the format string in the answer, just one with no place holders to replace. The answer you link to had a user provided format string. – Tanveer Badar Sep 01 '21 at 04:57
  • The only reason the OP uses `printf` here is because that's the way OP thought of to specify a numeric value for a single `char`-sized value (rather than using any kind of literal syntax). There are many other ways to do it. – Karl Knechtel Sep 01 '21 at 04:58
  • @TanveerBadar Correct - I just feel it's _best practice_ to default to using `puts` _until-or-unless_ you need formatted output - that way (eventually) you're less-likely to use `printf` to handle user-submitted strings. – Dai Sep 02 '21 at 05:33