hi all
i am trying to extract contents from a file, the content is the make up for other files e.g. the file would contain something like:
file1Rfile contents\n
Qfile2Rhello world\n
Q
now up until R is the file name and up until Q is the file contents
i am just having a small issue on the fact that i cannot get my program to move onto the next part in the buffer it just stops at the first file
i have been told by tabstop that i need a loop along with a way to empty the buffer every time it gets full as it is limited to 64 characters at the moment
so far i have:
Code:
char heading[64];
int x,len;
len=strlen(buffer);
for (x=0; x<=len; x++)
heading[x]=buffer[x];
while (heading[j] != '\0')
heading[j++];
if (heading[j+1] = 'R')
{
strncpy (buffera, heading, 5);
nwrite = open(buffera, O_CREAT, S_IRUSR|S_IWUSR);
while (heading[j] != '\0')
j++;
if (heading[j+1] = 'Q')
{
outfiledbody = open(buffera, O_CREAT | O_WRONLY | O_APPEND, S_IRUSR|S_IWUSR);
strncpy (bufferb, &heading[j], 5);
nwritebody = write(outfiledbody, bufferb, strlen(bufferb));
}
now i know there is alot of work to be done here!
where ive put strncpy (buffera, heading, 5); i dont mean for it to be only 5 characters that is for test purposes for now
with this code j for some reason equals 64, i have no idea how j became 64 although heading has 64 characters
i am hoping that this will get looping around properly so it can move on and create the second file
the previous code i used worked but only on the first file this is what that looked like:
Code:
char heading[64];
int x,len;
len=strlen(buffer);
for (x=0; x<=len; x++)
heading[x]=buffer[x];
char *pos = strchr(heading, 'R');
char *pos2 = strchr(heading, 'Q');
int posa = pos-heading;
int pos2a = pos2-heading;
int pos2b = pos2a - posa;
if (pos)
{
strncpy (buffera, heading, posa);
buffera[posa] = '\0';
nwrite = open(buffera, O_CREAT, S_IRUSR|S_IWUSR);
outfiledbody = open(buffera, O_CREAT | O_WRONLY | O_APPEND, S_IRUSR|S_IWUSR);
strncpy (bufferb, &heading[posa+1], pos2b);
bufferb[pos2b-1]='\0';
nwritebody = write(outfiledbody, bufferb, strlen(bufferb));
}