Wednesday, 4 July 2012

atoi is a function in the C programming language that converts a string into an integer numerical representation. atoi stands for ASCII to integer. It is included in the C standard library header file stdlib.h. Its prototype is as follows:

atoi : ASCII to integer

//INPUT : 24 83 0 2
//OUTPUT : 24 83 0 2
#include<stdio.h>
#include<string.h> int atoi(int K[10],char string[30]) { int j=0,i=0,temp=0; while(string[i]!='\0') { temp=0; while(string[i]!=' ' && string[i]!='\0') temp=temp*10 + (string[i++]-'0') ; if(string[i]==' ') i++; K[j++]=temp; } return j; }
int main() { char string[30]; int i,a,A[10]; printf("\nEnter String : "); gets(string); a=atoi(A,string); printf("\nIntegers are : "); for(i=0;i<a;i++) printf("%d ",A[i]); printf("\n"); return 0; }

No comments:

Post a Comment