Hi,

I need to populate a structure with the values from a string.I tried using strncpy but it did not work. Please let me know if any more details are required. Please find the below code and help me.
Code:
#include <stdio.h>
#include <string.h>

struct file
{
const char filename[2];
const char data[12];
const char data2[4];
};
struct file file1;

void main()
{
char a[25];
FILE *fp;

strcpy(a,"te this is test abcd");
strncpy(file1.filename,a,sizeof(file1));

fp=fopen(file1.filename,"w");
fwrite(file1.data,12,1,fp);
}
I need to populate the structure as:
filename:te
data:this is test
data2:abcd

Please help me
Thanks,
nan

Last edited by shabbir; 31Jul2008 at 16:28.. Reason: Code block