I have a char variable such as a = ' 123' or b = '\t123'. So how to convert them into integer? My problem is read form text file contains multi lines of char like a and b. I want to convert them and save to an array. Here is my code:
int main(){
FILE *file_pid;
int i = 0;
int number[100];
char line[20];
file_pid = fopen("pid.txt","r");
while(fgets(line, sizeof line, file_pid) != NULL){
number[i] = atoi(line);
i++;
}
}
Edited: I solved my problem. Many thanks!