Q:

Concatenating filename and filepath, path is splitted?

I have a program, that expects a file path and a part of the file name as input.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

char filename[3][50];

void main(int argc, char **argv)
{

    int run;
    run=atoi(argv[2]);

    char *datapath=malloc(100*sizeof(char));

    datapath=argv[1];

    sprintf(filename[0], "%s/test1.run%i", datapath, run);
    sprintf(filename[1], "%s/test2.run%i", datapath, run);
    sprintf(filename[2], "%s/test3.run%i", datapath, run);

}

But the resulting filename is separated to two strings. One containing
Name : filename
    Details:{"/home/test/data", "/test.run1", '\0' <repeats 74 times>, '\0' <repeats 49 times>}

Why?

A:

I don't see the problem. I modified your code a little bit:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

char filename[3][50];

void main(int argc, char **argv)
{

    int run;
    run=atoi(argv[2]);

    char *datapath=argv[1];

    sprintf(filename[0], "%s/test1.run%i", datapath, run);
    sprintf(filename[1], "%s/test2.run%i", datapath, run);
    sprintf(filename[2], "%s/test3.run%i", datapath, run);

    printf("filename[0]=%s\n", filename[0]);
    printf("filename[1]=%s\n", filename[1]);
    printf("filename[2]=%s\n", filename[2]);

}

And then ran it: 
$ gcc h.c -o h
$ ./h /home/test/data 1
filename[0]=/home/test/data/test1.run1
filename[1]=/home/test/data/test2.run1
filename[2]=/home/test/data/test3.run1

This is what you expected, right?

