Rabu, 24 Agustus 2016

Convert Char Array to Integer

Bismillahirrohmanirrohim
Bisa kalian gunakan fungsi ini mudah mudahan bermanfaat,jika merasa belum paham bisa ajukan pertanyaan di komentar atau contact facebook saya atau email fickrymhd@gmail.com

char buffer[4];

buffer[0] = command[1];
buffer[1] = command[2];
buffer[2] = command[3];
buffer[3] = '\0';

int  n;
n = atoi(buffer);
OR
char myarray[5] = {'-', '1', '2', '3', '\0'};
int i;
sscanf(myarray, "%d", &i);
OR
char myarray[4] = {'-','1','2','3'};
int i = atoi(myarray);

printf("%d\n",i);


Share:

0 comments:

Posting Komentar

Copyright © FILAB | Powered by FILAB
Design by Fickry Muhammad | Technology by Filab.id