how to convert string to integer in c

Converting String to Integer in C

To convert a string to an integer in C, you can use the atoi function from the stdlib.h library. Here's an example of how to use it:

#include <stdio.h>
#include <stdlib.h>

int main() {
    char str[] = "123";
    int num = atoi(str);
    printf("The integer is: %d\n", num);
    return 0;
}

This code snippet demonstrates how to convert the string "123" to the integer 123 using the atoi function.

Remember to include the necessary header files and handle error cases appropriately in your actual implementation.