atoi
I have a question about the atoi function... Why doesn't it convert a char into its ascii number?
1 2 3 4 5 6 7 8 9 10
|
#include<stdio.h>
#include<stdlib.h>
char c;
int n;
int main(void){
printf("Inserisici un carattere: ");
scanf("%c",&c);
n=atoi(c);
printf("\nNumero corrispondente: ");
}
|
It doesn't. It converts a c-string (a null terminated ascii string) into a number
1 2 3 4 5 6 7 8 9 10
|
#include<stdio.h>
#include<stdlib.h>
char c[100];
int n;
int main(void){
printf("Inserisici un carattere: ");
scanf("%s",&c);
n=atoi(c);
printf("\nNumero corrispondente: %d\n", n);
}
|
Inserisici un carattere: 12345
Numero corrispondente: 12345 |
oh thanks now i got it
Topic archived. No new replies allowed.