'how to access the i element of the void* string?
i have
void *string; // it is array of characters different encodings
i read it with my func, after that i want to print it, all good, it prints right. and after that i want to print i character (first for example), how can i access him?
string=readline();
printf("%s\n", string);
printf("%c\n", ??? );
i tried this, but it doesn't work
string=readline();
printf("%s\n", string);
printf("%c\n", string + sizeof(void *);
Solution 1:[1]
If the data is representable as char then simply cast and de-reference:
printf("%c\n", *(char*)string);
Or alternatively:
char* str = string;
...
printf("%c\n", str[i]);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lundin |
