Basic Posted November 4, 2007 at 05:21 PM Report Share #145206 Posted November 4, 2007 at 05:21 PM Boas precissava de ajuda numa coisa bastante simples mas que ja me esta a dar dores de cabeça tenho uma variavel que possui um valor ascii e precisso de saber o seu valor inteiro por exemplo char v = '#' int i = 35 Muito Obrigada Fica Bem Link to comment Share on other sites More sharing options...
Rui Carlos Posted November 4, 2007 at 06:10 PM Report Share #145214 Posted November 4, 2007 at 06:10 PM É simples, basta fazer um casting. int x=(int)'#'; Rui Carlos Gonçalves Link to comment Share on other sites More sharing options...
nDray Posted November 4, 2007 at 07:44 PM Report Share #145261 Posted November 4, 2007 at 07:44 PM de outro tópico.... #include <stdio.h> int main() { unsigned char a = 0; FILE *ascii = fopen("ascii.txt", "wt"); if(!ascii) { printf("somewhy failed\n"); return 1; } fprintf(ascii, "%5s%5s%5s%5s\n", "dec", "oct", "hex", "char"); do { fprintf(ascii, "%5d%5o%5x%5c\n", a, a, a, a); } while(++a != 0); printf("done"); return 0; } quanto ao cast... nem é necessário.... basta "int x = 'c'" Link to comment Share on other sites More sharing options...
garmg Posted November 5, 2007 at 01:15 AM Report Share #145322 Posted November 5, 2007 at 01:15 AM printf("a = %d\n", 'a'); 10 Useful Links Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now