I have 3 ".c" files called pre, sort and pipe. Pre takes a user input of names and GPA from a console. If the GPA is greater than or equal to 3.0, the name is stored into a struct.
Here's the pre.c file:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct student{
char temp_name[50];
char names[50];
};
int main()
{
int read_index = 0;
float check_gpa;
struct student data[read_index];
printf("Enter student name and GPA: \n");
scanf("%s %f\n", data[read_index].temp_name, &check_gpa);
read_index++;
while(scanf("%s %f\n", data[read_index].temp_name, &check_gpa) != EOF)
{
if (check_gpa >= 3.0)
{
strcpy(data[read_index].names, data[read_index].temp_name);
read_index++;
}
}
return 0;
}
The pipe file links the pre and sort files so that data from pre is sent to sort.
Here is the pipe.c file:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<string.h>
#include<sys/wait.h>
int main()
{
char *args[] = {"./sort", NULL};
char *argv[] = {"./pre", NULL};
int pipe_end[2];
int pipe_id;
pipe(pipe_end);
if (pipe(pipe_end)==-1) // Check for pipe functionality
{
perror("Pipe Failed");
return 1;
}
pipe_id = fork();
if (pipe_id < 0) //Check for fork functionality
{
printf("Fork failed");
return 1;
}
else if(pipe_id == 0)//Child
{
close(pipe_end[0]);
dup(pipe_end[0]);
execvp(argv[0], argv);
}
else //Parent
{
wait(NULL);
close(pipe_end[1]);
dup2(pipe_end[1], 0);
close(pipe_end[0]);
execvp(args[0], args);
}
return 0;
}
The sort file takes names from a struct array and sorts them alphabetically and prints them to the console. And this is where the problem starts, because when I run the pipe file i get to enter names and GPA's But when ever I initiate an EOF (which is required and cannot change) by pressing Ctrl+D, I'm expecting the strings to be sent over to sort and displayed alphabetically, however this doesn't happen.
Here's the sort.c file:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<string.h>
#include<sys/wait.h>
struct student{
char temp_name[50];
char names[50];
};
int main()
{
int print_index1 = 0,
print_index2,
read_index,
SIZE;
struct student data[print_index1];
SIZE = print_index1;
printf("Students with GPA's greater than or equal to 3.0, listed in alphabetical order:\n ");
for(print_index1 = 0; print_index1 < SIZE; print_index1++)
{
for(print_index2 = print_index1 + 1; print_index2 < SIZE; print_index2++)
{
if(strcmp(data[print_index1].names, data[print_index2].names) > 0)
{
strcpy(data[print_index1].temp_name, data[print_index2].names);
strcpy(data[print_index2].names, data[print_index1].names);
strcpy(data[print_index1].names, data[print_index1].temp_name);
}
}
printf("%s\n", data[print_index1].names);
}
return 0;
}
I've tested both files independently with user input and they worked. But a new problem has showed up, if you look at the sort file and notice I have a while loop that takes a for loop condition that I thought made sense> It worked a week ago but now it doesn't (unless it was a fluke). But that's my dilemma, I can't seem to get user input from "pre.c" over to "sort.c" I would really appreciate some help.
I also think the while loop in the "sort.c" file is causing an issue with printing the names.
Related
I think this is written in C, honestly don't know how to identify (if someone could give some tips it would be great). When the command rpt dumpvars 1234 is run in the console it returns the variables of machine/node 1234 to the screen. I want the same data output to a variables.txt file. Is there a simple one liner that I can add to do this?
The file is located here.
The portion of the data I am trying to get can be found on lines 7590-7623 as pasted here:
/*
* Display a node's main channel variables from the command line
*/
static int rpt_do_showvars(int fd, int argc, char *argv[])
{
int i,thisRpt = -1;
struct ast_var_t *newvariable;
if (argc != 3) return RESULT_SHOWUSAGE;
for(i = 0; i < nrpts; i++)
{
if(!strcmp(argv[2], rpt_vars[i].name))
{
thisRpt = i;
break;
}
}
if (thisRpt < 0)
{
ast_cli(fd, "Unknown node number %s.\n", argv[2]);
return RESULT_FAILURE;
}
i = 0;
ast_cli(fd,"Variable listing for node %s:\n",argv[2]);
ast_channel_lock(rpt_vars[thisRpt].rxchannel);
AST_LIST_TRAVERSE (&rpt_vars[thisRpt].rxchannel->varshead, newvariable,
entries) {
i++;
ast_cli(fd," %s=%s\n", ast_var_name(newvariable),
ast_var_value(newvariable));
}
ast_channel_unlock(rpt_vars[thisRpt].rxchannel);
ast_cli(fd," -- %d variables\n", i);
return(0);
}
Question: I have a file, called ATM1, and it is filled with strings, for example(this is the format for everyline): O ilan 123 456 Which means - O stands for open account, ilan is username, 123 is password, and 456 is initial amount in my bank account.
After opening the file, iterating with a while loop while(((ret_in = read (in1, &buffer1, BUF_SIZE)) > 0)), I want to get the line's details and store them in the appropriate variables. for example the first char will be stored in a variable called letter or msg[0] whatever is more convenient for you, then there is a space and then username, then password, and optional stuff like balance, or maybe another account id (for transfer money purposes).
Every ATM machine should be a thread, it has its own file, for now it is just one file "ATM1" because I want it to work in the beginning for at least one file.
Current Problem:
Segmentation fault in the OpenFile function. I'm still not able to store the line's values in the appropriate variables and called the switch statement for opening account, etc.
Here is the current code:
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <semaphore.h>
#define BUF_SIZE 8192
sem_t log;
void OpenNewAccount(int acc,int pw,int amount){
}
struct Account{
int number;
int password;
int balance;
};
//*Opens file for every ATM
void* openFile(void* args){
//To add later: while(true) { sleep(100); do next file's line }
//Open file
int* aargs = args;
int acc;
int pw;
int amount;
int target_acc;
int ret_in, in1,file;
char buffer1[BUF_SIZE];
int count = 0;
int i = 0;
char fn[5] = "ATM1";
char* msg;
file = open(fn,O_RDONLY|O_CREAT,0644);
while(((ret_in = read (file, &buffer1, BUF_SIZE)) > 0))
{
for(i; i<ret_in; i++)
{
if(buffer1[i]!='\n')
msg[i] = buffer1[i];
/* else{
if(count == 0){
count++;
break;
}
else
{
count = i + 1;
break;
}
}
*/
}
}
printf("%s", msg); //TEST: check msg
//Here we translate the message
/*
//Here we call the relevant function of the msg
switch (msg[count - 1]){
case 'O': OpenNewAccount(acc,pw,amount);
case 'D': Deposit(acc,pw,amount);
case 'W': Withdrawl(acc,pw,amount);
case 'B': Balance(acc,pw);
case 'Q': CloseAccount(acc,pw);
case 'T': Transfer(acc,pw,target_acc,amount);
}
*/
}
//*finish: Update log.txt and lock it
void WriteLog(char* msg){
int file;
char logName[8] = "log.txt";
sem_wait(&log);
file = open(logName,O_WRONLY|O_CREAT,0644);
strcat(msg,"\n");
write(file,&msg,strlen(msg));
close(file);
sem_post(&log);
}
int main(void)
{
int i,n,a;
sem_init(&log, 0, 1);
printf("Please enter the number of ATMs you want: \n");
scanf("%d", &n);
int bank; //bank with n ATMs
pthread_t thread[3];
printf("test\n"); //TEST: check msg
for(i = 0; i < 3; i++)
pthread_create ( &thread[i] , NULL , openFile , &i);
scanf("%d",&a);
}
Well, for one, you use i as an array index without ever initializing it. That could easily cause a SEGFAULT.
But honestly this whole thing is a mess. Your function names don't do what they say they do. You appear to be thrashing around almost randomly. I suggest you rethink your design from the beginning. Go through the "top down" design process you should have learned and figure out how to factor your code. Only then should you proceed.
I am a starter to work with shared memory and I have implemented a parallel adder in which each of the k processors is implemented as a child process. Specifically, given a set of n integers and value of k, the main program creates k child processes, assigns each child process to compute the total of its assigned ceiling of n/k numbers, waits for the sub-total from each of the k child processes, sum up the sub-totals, and print the result of each sub-total as well as the overall total. I have not use threads.
This program is created for assignment in the college and they it is expected to run in any department computer.
This code correctly compile on Kali Linux but I can not compile and run on other Linux versions.
When I tried to compile on Ubuntu it gives the error saying
undefined reference to 'sem_init'
I used -lrt in the line of compiling. Please help me with this problem.
This is the code that I created.
#include<stdio.h>
#include<sys/ipc.h>
#include<sys/wait.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<fcntl.h>
#include<errno.h>
#include<semaphore.h>
#include<unistd.h>
#include<math.h>
#include<stdlib.h>
#define BUFFER_SIZE 100
#define BUFFER_SUB 2
typedef struct
{
int bufMax;
int datalimit;
int buff[BUFFER_SIZE];
sem_t mutex, empty, full;
} shared_inputs;
typedef struct
{
int sub[BUFFER_SUB];
sem_t mutex,empty,full;
}sub_tot;
int main(int argc, char *argv[])
{
int x = 0;
int data,count,i,j,tot;
int n;
int k =atoi(argv[2]);
int assign_size;
count = tot =0;
int segment_id;
size_t segment_size = sizeof(shared_inputs);
segment_id = shmget(IPC_PRIVATE,segment_size,IPC_CREAT|0666);
shared_inputs *shared_memory = shmat(segment_id,NULL,0);
sem_init(&shared_memory->mutex,1,1);
sem_init(&shared_memory->empty,1,BUFFER_SIZE);
sem_init(&shared_memory->full,1,0);
int segment_idSubs;
size_t segment_size1 = sizeof(sub_tot);
segment_idSubs = shmget(IPC_PRIVATE,segment_size1,IPC_CREAT|0666);
sub_tot *subtotal = shmat(segment_idSubs,NULL,0);
sem_init(&subtotal->mutex,1,1);
sem_init(&subtotal->empty,1,BUFFER_SUB);
sem_init(&subtotal->full,1,0);
FILE *numFile;
numFile = fopen(argv[1], "r");
while(!feof(numFile))
{
fscanf(numFile,"%d",&data);
sem_wait(&shared_memory->empty);
sem_wait(&shared_memory->mutex);
shared_memory->buff[x] = data;
sem_post(&shared_memory->mutex);
sem_post(&shared_memory->full);
printf("%d ", shared_memory->buff[x]);
x++;
n = x;
}
assign_size = ceil((double)n/(double)k);
printf("\n");
shared_memory->datalimit = 0;
shared_memory->bufMax = n-1;
printf("assigned size : %d \n", assign_size);
printf("n : %d , k : %d \n",n,k);
for(i =0; i < k; i++)
{
int id;
int subt = 0;
id = fork();
if(id < 0) // error in fork
{
perror("Error in fork ");
exit(300);
}
else if(id == 0)//the new child process
{
for(j=0;j< assign_size; j++)//getting items from the shared memory
{
sem_wait(&shared_memory->full);
sem_wait(&shared_memory->mutex);
int num = shared_memory->buff[shared_memory->datalimit];
//printf("%d \n",shared_memory->buff[shared_memory->datalimit]);
shared_memory->datalimit++;
sem_post(&shared_memory->mutex);
sem_post(&shared_memory->empty);
subt = subt + num;
if(shared_memory->datalimit == shared_memory->bufMax)
{
break;
}
}
int pid = getpid();
sem_wait(&subtotal->empty);
sem_wait(&subtotal->mutex);
subtotal->sub[0] = pid;
subtotal->sub[1] = subt;
sem_post(&subtotal->mutex);
sem_post(&subtotal->full);
printf("Sub-total produced by Processor with ID %d: %d \n",pid,subt);
exit(0);
}
else//parent process
{
int status;
wait(&status);
sem_wait(&subtotal->full);
sem_wait(&subtotal->mutex);
int sub = subtotal->sub[1];
sem_post(&subtotal->mutex);
sem_post(&subtotal->empty);
tot = tot+sub;
}
}
printf("Total: %d \n",tot);
return 0;
}
Need to add -lpthread when compiling and use -lm and -lrt also.
You need to add #include <pthread.h> in order to make it work
Processor.c
#include<time.h>
#include<stdio.h>
#include<pthread.h>
#include<semaphore.h>
#include<string.h>
#include<stdlib.h>
#include<malloc.h>
#include<unistd.h>
#include"Process_struct.h"
sem_t empty;//semaphores
#define MAX_PROCS 5
#define EXIT 1
#define TRUE 1
char outbaseStr [100];
int numProcessors;
FILE *outLog=NULL;
FILE *file=NULL;
FILE *outFile=NULL;
FILE *temp=NULL;
pthread_t producer;//Producer Thread ID
pthread_t consumer[MAX_PROCS];//consumer thread ID
int main(int argc, char *argv[])
{
/* Initialize Data */
initializeData();
printf("argc equals %d\n", argc);
int num_processors=atoi(argv[2]);
int case_num=atoi(argv[3]);
char filename;
char *outfilename=argv[1];
printf("outfilename equals %s\n", outfilename);
printf("num_processors equals %d\n\n", num_processors);
switch(case_num)
{
case 1:
//printf("case 1\n");
/* Reading in from the text */
file = fopen("temp.txt", "wr");
/* fopen returns 0, the NULL pointer, on failure */
if(file==0||file==NULL)
{
printf("Error: couldn't open the file\n");
exit(EXIT);
}
/*****************************************************************************/
//write to temp
int length=argc-4;
for(int i=0;i<length;i++)
{
if(i%2==0)
{
//printf("%d ", atoi(argv[i+3]));
fprintf(file, "%d ", atoi(argv[i+4]));
}
else
{
//printf("%d\n", atoi(argv[i+3]));
fprintf(file,"%d\n", atoi(argv[i+4]));
}
}
/*****************************************************************************/
fclose(file);
file = fopen("temp.txt", "r");
/* Create the producer thread */
pthread_create(&producer, NULL, get_request, (void *)file);
break;
case 2:
//char filename[100];
//filename=argv[3];
//printf("usage: %s filename\n", argv[3]);
/* Reading in from the text */
file = fopen(argv[4], "r");
/* fopen returns 0, the NULL pointer, on failure */
if(file==0||file==NULL)
{
printf("Error: couldn't open the file\n");
exit(EXIT);
}
/* Create the producer thread */
pthread_create(&producer, NULL, get_request, (void *)file);
break;
default:
printf("Error: should be either case 1 or case 2\n");
exit(EXIT);
break;
}
pthread_join(producer, NULL);
//displayQ();
// Create the consumer threads
for(int i=0;i<num_processors;i++)
{
sprintf(outbaseStr, "%s.%ld", outfilename, (long)(i+1));
//printf("outbaseStr equals %s\n", outbaseStr);
outLog=fopen(outbaseStr, "w");
if(outLog==NULL)
{
printf("Error: couldn't open the file\n");
exit(EXIT);
}
pthread_create(&consumer[i], NULL, processor, (void *)outLog);
}
for(int i=0;i<num_processors;i++)
{
pthread_join(consumer[i], NULL);
}
//printf("\nfclose\n");
close((FILE *)file);
//fclose((FILE *)file);
if(case_num==1)
{
if(remove("temp.txt")!=0)
{
printf("error deleting file");
}
else
{
//printf("success deleting file");
}
}
}
Process_struct.c
#include<time.h>
#include<stdio.h>
#include<pthread.h>
#include<semaphore.h>
#include<string.h>
#include<stdlib.h>
#include<malloc.h>
#include<unistd.h>
#include"Process_struct.h"
sem_t empty;//semaphores
#define MAX_PROCS 5
#define EXIT 1
#define TRUE 1
char outbaseStr [100];
int numProcessors;
FILE *outLog=NULL;
FILE *file=NULL;
FILE *outFile=NULL;
FILE *temp=NULL;
pthread_t producer;//Producer Thread ID
pthread_t consumer[MAX_PROCS];//consumer thread ID
void initializeData()
{
//printf("initializeData\n");
//Create the empty semaphore and initialize it
sem_init(&empty, 0, MAX_PROCS);
// pthread_attr_init(attr);
}
void *get_request(void *argv)//this produces a queue
{
prcmd_t *process;
//printf("get_request\n");
if(file==NULL)
{
printf("\nwe have a file null error\n");
}
while(!feof(file))
{
process=(prcmd_t *)malloc(sizeof(prcmd_t));
fscanf(file, "%d %d", &process->owner, &process->burst_time);
if(process->owner!=0||process->burst_time!=0)
{
//printf("%d %d\n", process->owner, process->burst_time);
if(add_queue(process)==-1)
{
printf("failure from add_queue");
}
}
}
//printf("this is the end of get_request\n");
}
void *processor(void *argv)//this consumes a queue
{
prcmd_t *process;
// process=(prcmd_t *)malloc(sizeof(prcmd_t));
process=pr_head;
int sleep_time=process->burst_time;
//printf("\nprocessor\n");
while(TRUE)
{
if(get_number_request()>0)
{
if(remove_queue(&process)==0)
{
fprintf(outLog, "\n->Process with id %d and it %d de-equeue by thread \n", process->owner, process->burst_time);
clock_t start=clock();
sleep(process->burst_time);
clock_t end=clock();
fprintf(outLog, "\nSlept for %d seconds\n", sleep_time);
}
}
close((FILE *)outLog);
//fclose((FILE *)outLog);
//printf("the end of the processor\n");
//displayQ();
return NULL;
}
}
int get_number_request()
{
return pending_request;
}
void displayQ()
{
printf("\n\nthis is the beginning of displayQ\n");
prcmd_t *process=pr_head;
do
{
printf("%d %d\n", process->owner, process->burst_time);
process=process->next;
}while(process!=NULL);
printf("\nthe end of displayQ\n\n");
}
int add_queue(prcmd_t *node)
{
prcmd_t *temp;
temp=node;
pthread_mutex_lock(&prmutex);
//printf("add_queue\n");
//printf("%d %d\n", temp->owner, temp->burst_time);
/* adding a linkedlist to a queue */
if(pr_head==NULL)//then pr_tail==NULL
{
//printf("pr_head==NULL\n");
temp->next=NULL;
pr_head=temp;
pr_tail=temp;
}
else
{
//printf("pr_head!=NULL\n");
temp->next=NULL;
pr_tail->next=temp;
pr_tail=temp;
}
pending_request++;
pthread_mutex_unlock(&prmutex);
//printf("add_queue success\n");
return(0);
}
int remove_queue(prcmd_t **node)
{
//printf("\nremove_queue/enqueue\n");
pthread_mutex_lock(&prmutex);
prcmd_t *temp;
// printf("this is the end of remove_queue/enqueue and is returning 0\n");
if(pr_head==NULL)
{
//printf("pr_head==NULL");
pr_head = pr_tail = NULL; // Reset everything to empty queue
pthread_mutex_unlock(&prmutex);
//printf("this is the end of remove_queue/enqueue and is returning -1\n");
return(-1);
}
else
{
//printf("pr_head!=NULL\n");
temp=pr_head;
temp->next=pr_head->next;
pr_head=temp->next;
pending_request--;
pthread_mutex_unlock(&prmutex);
//printf("this is the end of remove_queue/enqueue and is returning 0\n");
return(0);
}
}
Process_struct.h
GNU nano 2.2.6 File: Process_struct.h
#include<time.h>
#include<stdio.h>
#include<pthread.h>
#include<semaphore.h>
#include<string.h>
#include<stdlib.h>
#include<malloc.h>
#include<unistd.h>
typedef struct pr_struct
{
int owner;
int burst_time;
struct pr_struct *next;
} prcmd_t;
void displayQ();//this displays the queue
void initializeData();//initializes the data for the program
void *get_request(void *args);//to be calls as a thread to enqueue input reques$
void *processor(void *args);//which removes a request from the process request $
int get_number_request();//returns the number of request
int add_queue(prcmd_t *);//adds a node at the end of the request queue
int remove_queue(prcmd_t **);//removes a node for the queue
#define MAX_PROCS 5
#define EXIT 1
#define TRUE 1
This is the error I have:
/tmp/ccvDJUQI.o:(.bss+0x0): multiple definition of `outLog'
/tmp/cc4RWdZ4.o:(.bss+0x0): first defined here
/tmp/ccvDJUQI.o:(.bss+0x8): multiple definition of `file'
/tmp/cc4RWdZ4.o:(.bss+0x8): first defined here
/tmp/ccvDJUQI.o:(.bss+0x10): multiple definition of `outFile'
/tmp/cc4RWdZ4.o:(.bss+0x10): first defined here
/tmp/ccvDJUQI.o:(.bss+0x18): multiple definition of `temp'
/tmp/cc4RWdZ4.o:(.bss+0x18): first defined here
collect2: error: ld returned 1 exit status
make: *** [Multiprocessor] Error 1
Whenever I go to run my make file this is the error I get. I don't understand where the error would be so I can't find it and change it. I was hoping someone could tell me what collect2: error: ld returned 1 exit status means and where the error would be at.
From your comment, it looks like you're trying to compile header files
gcc Processor.c Process_struct.h Process_struct.c -o Multiprocessor -std=c99 -lm -lpthread
A header file is included in a .c file and not compiled separately. Your command line should more look like
gcc Processor.c Process_struct.c -o Multiprocessor -std=c99 -lm -lpthread
Another source of this kind of errors, is when you define variables in a header file and include the header file in multiple source files, e.g. in Process_struct.h
FILE *file = NULL;
char temp[] = "/tmp";
When you include this header file in Processor.c and Process_struct.c, you define these variables in both sources and as a consequence get multiple defined variables.
To fix this, you must not define, but only declare the variables in the header file. You can then define them in one source file, e.g.
Process_struct.h:
extern FILE *file;
extern char temp[];
and in Process_struct.c:
FILE *file = NULL;
char temp[] = "/tmp";
Yet another source of multiple definitions is just that, you have defined the same variable in multiple places. This means when you have
Processor.c:
FILE *file = NULL;
char temp[] = "/tmp";
Process_struct.c:
FILE *file = NULL;
char temp[] = "/tmp";
you will get this error. The fix for this depends on your intention. If these variables are local to the file (independent from each other) narrow their scope to the file by prefixing with static
static FILE *file = NULL;
static char temp[] = "/tmp";
However, if you want to share the variables between these two sources, you must keep one definition and make the other one a declaration only. Better yet, move the declaration to a header file and keep the definition in only one source file, as in the second part above.
In any case, you should structure your makefile a bit differently. Use the built-in rules as much as possible, see Using Implicit Rules. E.g.
CFLAGS = -std=c99 -pthread
LDLIBS = -lm -lpthread
OBJS = Processor.o Process_struct.o
Multiprocessor: $(OBJS)
$(CC) $(CFLAGS) -o $# $(OBJS) $(LDLIBS)
For all user looking for an answer to collect2: error: ld returned 1 exit status, remember that it is helpful to make all the variables in your header file a STATIC variable. That's what made my error go away so to all other users that could be the answer to your error.
I have edited my previous question.
As I had got the problem and the changed the code, now I have a different problem. If I use execle command, it only downloads one image using the wget command, otherwise it prints all the image names on the screen if the wget command does not execute. I do not understand when there is a while loop, then why does it only print one image.
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
#include<limits.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<stdio.h>
void main(int argc, char*argv[])
{
int iFlag;
char cline[100];
FILE*fil = fopen("index.html","rt");
if(fil==NULL)
{
printf("Error in opening file");
}
char*tmpLine;
char*tok;
const char check[10] = "<img";
const char check2[10] = "src=";
char images[50];
strcpy(images,argv[1]);
while(fgets(cline,100,fil)!=NULL)
{
if(strstr(cline,check)!=NULL)
{
tmpLine=strstr(cline,check);
if(strstr(cline,check2)!=NULL)
{
tmpLine=strstr(cline,check2);
tok = strtok(tmpLine,"\"");
while(tok!=NULL)
{
tok = strtok(NULL,"\"");
if(tok[0]!='/')
{
strcat(images,"/");
strcat(images,tok);
printf("\nimage: %s\n",images);
iFlag = execle("/usr/bin/wget","wget","-o","logfile",images,NULL);
if(iFlag<0)
perror("EXECLE ERROR");
break;
}
else
break;
}
memset(&images[0], 50, sizeof(images));
strcpy(images,argv[1]);
}
}
}
}
A big problem is that the exec family of function replaces your process with that of the new program. That means that if the call to execle succeeds your program no longer exists.
You need to fork a new process if you want your own program to continue.