Answers for "c get int from char array"

C
1

char array to int c

char myarray[5] = {'-', '1', '2', '3', ''};
int i;
sscanf(myarray, "%d", &i);
Posted by: Guest on March-29-2021
-2

How to return a char array from a function in C

#include <stdio.h>
#include <string.h>
    char* createStr(){
    static char str[20] = "my";
    return str;
}
int main(){
    char a[20];
    strcpy(a,createStr()); //this will copy the returned value of createStr() into a[]
    printf("%s",a);
    return 0;
}
Posted by: Guest on July-01-2021

Code answers related to "C"

Browse Popular Code Answers by Language