code a voir

PHOTO EMBED

Tue Jun 27 2023 00:32:02 GMT+0000 (Coordinated Universal Time)

Saved by @thefirewall #html

#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*/
content_copyCOPY

how to convert string to number