Preview:
#include <stdio.h>
/**
 * _atoi - converts string to integer
 *@s: pointer to char
 * Return: int
 */


int _atoi(char *s)
{
int nb_sign_minus = 0;
char *s2 ;
int res  = 0;
int  *ptres = &res; 
while (*s)
{
/*test first character */

if (*s == '-')
nb_sign_minus++;
if(*s >= '0' && *s <= '9') /*ifx1*/
{ s2 = s;
if (nb_sign_minus % 2 != 0 )
{
*ptres = '-'; /*printf("%c", '-');*/
ptres++;
}
while (*s2 != '\0' && (*s2 >= '0' && *s2 <= '9'))
{
*ptres = *s2 ; /*printf("%c", *s2);*/
s2++;
ptres++;
} /* end while loop*/
s  = s2  ;
s2 = '\0';
nb_sign_minus = 0;
} /*end ifx1 */   
} /*principal while */
return res;
} /*end method*/
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter