Hello, i can't find why my program go to segfault.
If i type in console "./vcpl file_that_doesnt_exist" it print "... No such file or directory".
But if i type "./vcpl fiel_that_exit" it print "segmentation fault"!
I can't understand why
Please help me
main.c:
Code:
#ifdef __linux__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "c_vector.h"
#include "vcpl.h"
int main(int argc, char **argv)
{
FILE *input;
vcplOptions *options = (vcplOptions *)malloc(sizeof(struct vcplOptions));
char c;
char LineBuffer[255];
strcpy(LineBuffer, "");
if(argc < 2)
{
printf("Usage error!\n");
return -1;
}
input = fopen(argv[1], "r");
if(input == 0)
{
printf("(vcpl) %s: No such file or directory", argv[1]);
fclose(input);
return -1;
}
else
{
options->InputName=argv[1];
/* Get file's lines */
while((c = fgetc(input)) != EOF)
if(c == '\n')
options->Lines++;
fsetpos(input, 0);
/* Read code from file and store it into a variable-size vector node (like C++'s STL's vector class)*/
/* Init vector */
vector Vector;
vector_init(&Vector);
while(!feof(input))
{
c = fgetc(input);
if(c == '\n')
{
vector_set(&Vector, (vector_count(&Vector) - 1), LineBuffer);
vector_add(&Vector, "");
strcpy(LineBuffer, "");
}
else strcat(LineBuffer, (char *)c);
}
for(int i = 0; i < vector_count(&Vector) ; i++)
printf("%s", (char *)vector_get(&Vector, i));
/* Exit */
fclose(input);
free(options);
return 0;
}
}
#endif
Bookmarks