I'm new to C and to the Ubuntu os, I have three files: main.c, dosomething.c, dosomething.h
main.c
#include <stdio.h>
#include <stdlib.h>
#include "dosomething.h"
int main(int argc, char *argv[])
{
int i;
char *source;
if(argc < 2)
{
printf("Error: too few arguments, at least one file required");
exit(EXIT_FAILURE);
}
for(i = 1; i < argc; i++)
{
source = argv[i];
buildam(source);
}
exit(0);;
}
dosomething.h
void buildam(char *filename);
dosomething.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "dosomething.h"
void buildam(char *filename)
{
char *filename2 = "";
strcpy(filename2, filename);
printf("%s", filename2);
}
Now when I run this program (it has no problem compiling with gcc) on an input file, it throws this eror:
Segmentation fault (core dumped)
I've tried to debug using gdb, main.c was working fine until i got into "buildam" function, when the debugger threw the following error:
Program received signal SIGSEGV, Segmentation fault.
__strcpy_ssse3 () at ../sysdeps/i386/i686/multiarch/strcpy-ssse3.S:2876
2876 ../sysdeps/i386/i686/multiarch/strcpy-ssse3.S: No such file or directory
I don't have a clue what does it mean or how can i fix it, I'll be glad to understand it.