Program's Purpose: Rune Cipher
Note - I am linking to my Own GitHub page below (it is only for purpose-purpose (no joke intended; it is only for the purpose of showing the purpose of it - what I needed help with (and got help, thanks once again to all of you!)
Final Edit:
I have now (thanks to the Extremely Useful answers provided by the Extremely Amazing People) Completed the project I've been working on; and - for future readers I am also providing the full code.
Again, This wouldn't have been possible without all the help I got from the guys below, thanks to them - once again!
Original code on GitHub
Code
(Shortened down a bit)
#include <stdio.h>
#include <locale.h>
#include <wchar.h>
#define UNICODE_BLOCK_START 0x16A0
#define UUICODE_BLOCK_END 0x16F1
int main(){
setlocale(LC_ALL, "");
wchar_t SUBALPHA[]=L"ᛠᚣᚫᛞᛟᛝᛚᛗᛖᛒᛏᛋᛉᛈᛇᛂᛁᚾᚻᚹᚷᚳᚱᚩᚦᚢ";
wchar_t DATA[]=L"hello";
int lenofData=0;
int i=0;
while(DATA[i]!='\0'){
lenofData++; i++;
}
for(int i=0; i<lenofData; i++) {
printf("DATA[%d]=%lc",i,DATA[i]);
DATA[i]=SUBALPHA[i];
printf(" is now Replaced by %lc\n",DATA[i]);
} printf("%ls",DATA);
return 0;
}
Output:
DATA[0]=h is now Replaced by ᛠ
...
DATA[4]=o is now Replaced by ᛟ ᛠᚣᚫᛞᛟ
Question continues below
(Note that it's solved, see Accepted answer!)
In Python3 it is easy to print runes:
for i in range(5794,5855):
print(chr(i))
outputs
ᚢ ᚣ (..) ᛝ ᛞ
How to do that in C ?
- using variables (char, char arrays[], int, ...)
Is there a way to e.g print ᛘᛙᛚᛛᛜᛝᛞ as individual characters?
When I try it, it just prints out both warnings about multi-character character constant 'ᛟ'
.
I have tried having them as an array of char, a "string" (e.g char s1 = "ᛟᛒᛓ";)
- And then print out the first
(ᛟ)
char of s1:printf("%c", s1[0]);
Now, this might seem very wrong to others.
One Example of how I thought of going with this:
Print a rune as "a individual character":
To print e.g 'A'
printf("%c", 65); // 'A'
How do I do that, (if possible) but with a Rune ?
I have as well as tried printing it's digit value to char, which results in question marks, and - other, "undefined" results.
As I do not really remember exactly all the things I've tried so far, I will try my best to formulate this post.
If someone spots a a very easy (maybe, to him/her - even plain-obvious) solution(or trick/workaround) -
I would be super happy if you could point it out! Thanks!
This has bugged me for quite some time.
It works in python
though - and it works (as far as I know) in c
if you just "print" it (not trough any variable) but, e.g: printf("ᛟ");
this works, but as I said I want to do the same thing but, trough variables. (like, char runes[]="ᛋᛟ";)
and then: printf("%c", runes[0]); // to get 'ᛋ' as the output
(Or similar, it does not need to be %c
, as well as it does not need to be a char array/char variable) I am just trying to understand how to - do the above, (hopefully not too unreadable)
I am on Linux, and using GCC.
char *a[] = { "ᛘ","ᛙ","ᛚ","ᛛ","ᛜ","ᛝ","ᛞ" };
thenprintf("%s\n", a[5]);
– Plagalwchar_t
– Dominquedominquezchar
s are bytes, and runes are clearly not in those 0-255 range, since its default encoding is ASCII, you can usemulti byte encoding
like utf8, and functions likeprintf
(not on each system though) can actually understand that and print it correctly. So forᚢ
character it will be 3 bytes:[0xE1 0x9A 0xA2]
, try it out:char n[4] = {0xe1, 0x9a, 0xa2, '\0'};printf("%s\n", n);
– Swollen