Question: Please help me figure out why im getting this error, warning: passing argument 1 of atoi from incompatible pointer type [ - Wincompatible - pointer

Please help me figure out why im getting this error, "warning: passing argument 1 of atoi from incompatible pointer type [-Wincompatible-pointer-types]
int num = atoi(arg_str)-'0';" and help me make sure my code will print what it is supposed to in the first picture
Generator.c
#include
#include
#include
#include
#include
int main(int argc, char *argv[]){
pid_t pid;
FILE *fp = fopen(argv[1],"r");
if (!fp){
perror("File open failed");
exit(EXIT_FAILURE);
}
size_t listSize =1000;
size_t lineCount =0;
char **list = malloc(listSize * sizeof(char *));
char line[256];
// Reading lines from the file
while (fgets(line, sizeof(line), fp)){
list[lineCount]= malloc(strlen(line)+1);
strcpy(list[lineCount], line);
lineCount++;
// Resize list if needed
if (lineCount >= listSize){
listSize *=2;
list = realloc(list, listSize * sizeof(char *));
}
}
fclose(fp);
for (int i =0; i lineCount; i++){
printf("Generator Process: Processing line \"%s\"
", list[i]);
// Forking a child process
pid = fork();
char *program;
char *arg_str = list[i];
if (pid 0){
perror("Fork failed");
exit(EXIT_FAILURE);
} else if (pid ==0){
// In the child process
program ="./Fibonacci";
execlp(program, program, arg_str,(char *)NULL);
perror("execlp failed"); // This line is only reached if execlp fails
exit(EXIT_FAILURE);
} else {
// In the parent process
int status1;
wait(&status1); // Wait for the child to finish
if (WIFEXITED(status1)){
int result1= WEXITSTATUS(status1);
program ="./Fibonacci";
printf("%s Process finished (PID: %d). Returned: %d
", program, pid, result1);
pid = fork();
if (pid 0){
perror("Fork failed");
exit(EXIT_FAILURE);
} else if (pid ==0){
program ="./Perrin";
execlp(program, program, result1,(char *)NULL);
perror("execlp failed"); // This line is only reached if execlp fails
exit(EXIT_FAILURE);
} else {
// In the parent process
int status2;
wait(&status2); // Wait for the child to finish
if (WIFEXITED(status2)){
int result2= WEXITSTATUS(status2);
printf("%s Process finished (PID: %d). Returned: %d
", program, pid, result2);
pid = fork();
if (pid 0){
perror("Fork failed");
exit(EXIT_FAILURE);
} else if (pid ==0){
// In the child process
program ="./Composite";
// Replace current process with new program
execlp(program, program, result2,(char *)NULL);
perror("execlp failed"); // This line is only reached if execlp fails
exit(EXIT_FAILURE);
} else {
// In the parent process
int status3;
wait(&status3); // Wait for the child to finish
if (WIFEXITED(status3)){
int result3= WEXITSTATUS(status3);
printf("%s Process finished (PID: %d). Returned: %d
", program, pid, result3);
} else {
printf("Child process did not terminate normally.
");
}
}
} else {
printf("Child process did not terminate normally.
");
}
}
} else {
printf("Child process did not terminate normally.
");
}
}
}
// Free memory
for (int i =0; i lineCount; i++){
free(list[i]);
}
free(list);
return 0;
}
Please help me figure out why im getting this

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!