I know the segfault is located within the argv[y] but I don't understand why! I'm very new to UNIX and rusty on my C. Any help would be awesome. (printfs were a messy way to find where the segfault was!)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define PAGELEN 24
#define LINELEN 512
void do_more(FILE *);
int see_more();
int main(int argc, char *argv[])
{
FILE *fp;
int i;
int loc;
int x;
int y;
char buffer[LINELEN];
FILE *t;
FILE *out;
FILE *read;
for(i=1; i<argc; i++){
if(strcmp(argv[i], "-o") == 0)
loc = i;
else if((t = fopen(argv[i], "r")) != NULL){
x = i;
fclose(t);
}
else{
y = i;
}
}
if(loc != -1){
FILE *read;
printf("1");
read = fopen(argv[x], "r");
printf("2");
out = fopen(argv[y], "w");
printf("3");
while(fgets(buffer, LINELEN, read))
printf("4");
fputs(buffer, out);
printf("5");
fclose(read);
fclose(out);
}
}