i created a program which will read some data from an array, filter some out and copy the useful part (filtering stage). it will then use some of the info to create a directory with the name taken from the data. then it will dump the original data into a file in the directory create.

the directory structure is PRN>>Year>>Day>>hour(file)

howver, i have managed to successfully create the directories and filter the data in sperate files.

when i came to putting it together it refuses to work.

there are no errors but it wont do what its supposed to.

so far, it creates the directories but doesnt dump the data

can anyone give me a hand, please?

Code:
#include <string.h>
#include <stdio.h>
#include <windows.h>
#include <io.h>

int main ()  
  
{
	char streaminput[BUFSIZ] =
        "#RAWWAASFRAMEA,COM1,9,68.0,SATTIME,1263,126458.000,00000000,58e4,1522,22,122,62,5663456345dba43623443efdaef3245345fea32534562663462323c000,22*d04567cde";

    char wasteitems[BUFSIZ] = "#RAWWAASFRAMEA SATTIME COM ; , * .";

//	int PRN = 152;   //*************************************
    int hour = 4;    //*********FOR TEST PURPOSE************
    int day = 146;   //*********REMOVE BEFORE USE***********
    int year = 2008; //*************************************
	char decoded[1];                            //*************************************
//    char decodPRN[10] = "122";                  //*********FOR TEST PURPOSE************
    char decoddate[12] = " 26 06 05";           //*************************************
    char decodtime[12] = " 13 59 59";           //*********REMOVE BEFORE USE***********
//    char decodmsgtype[10] = " 69";              //*************************************
//    char decodmsg[100] = " 9acasdacadad23523d"; //*************************************
	char *firstfilter;
    char *secondfilter;
    char *thirdfilter;
    char *fourthfilter;
    char *fifthfilter;
    char *sixthfilter;
    char *seventhfilter;
    char *eigthfilter;
    char *ninthfilter;
    char *tenthfilter;
    char *eleventhfilter;
    char *twelvthfilter;
    char *thirteenthfilter;
    char *fourteenthfilter;
    char *fifteenthfilter;

	//These will be taken each time from the filtered stream input//
//***********************************************************************
    char decodPRN[BUFSIZ];  //string for PRN name
    char decodyear[BUFSIZ]; //string for year
    char decodday[BUFSIZ];  //string for day
    char decodmsgtype[BUFSIZ]; //string for msgtype
    char decodmsg[BUFSIZ];	//string for msg
//***********************************************************************

	{

    printf("remaining data:\n");

    firstfilter = strtok(streaminput, wasteitems);

 //****************recursive filtering to seperate sections and assign strings************//

    secondfilter = strtok(NULL, wasteitems);
    thirdfilter = strtok(NULL, wasteitems);
    fourthfilter = strtok(NULL, wasteitems);
    fifthfilter = strtok(NULL, wasteitems);
    sixthfilter = strtok(NULL, wasteitems);
    seventhfilter = strtok(NULL, wasteitems);
    eigthfilter = strtok(NULL, wasteitems);
    ninthfilter = strtok(NULL, wasteitems);
    tenthfilter = strtok(NULL, wasteitems);
    eleventhfilter = strtok(NULL, wasteitems);
    twelvthfilter = strtok(NULL, wasteitems);
    thirteenthfilter = strtok(NULL, wasteitems);
    fourteenthfilter = strtok(NULL, wasteitems);
    fifteenthfilter = strtok(NULL, wasteitems);
	
//*******************copy useful parts of masg and ingore rest******************//
    strcpy(decodPRN, fifthfilter);
    strcpy(decodday, secondfilter);
    //strcpy(uncodtime, sixthfilter);  //not needed yet**constant defined earlier//
    strcpy(decodmsgtype, thirteenthfilter);
    strcpy(decodmsg, fourteenthfilter);
    //strcpy(uncodCRC, sixteenthfilter); /not needed yet**constant defined earlier//

    //sixteenthfilter = strtok( NULL, wasteitems );  //not needed yet**constant defined earlier//


//******Checks to see if PRN exists and creates new directory if statement if false*********\\ 

    sprintf(decodPRN, "c:\\temp\\PRN%3d", decodPRN);
    SetCurrentDirectory(decodPRN); //sets directory to current PRN

    if (SetCurrentDirectory(decodPRN) == NULL)
        printf("\n\n\nNew PRN detected and folder created\n\n\n");

    CreateDirectory(decodPRN, NULL);

//******Checks to see if year exists and creates new directory if statement if false********\\ 

    sprintf(decodyear, "c:\\temp\\PRN%3d\\Y%4d", decodPRN, year);
    SetCurrentDirectory(decodyear); //sets directory to current year

    if (SetCurrentDirectory(decodyear) == NULL)
        printf("\n\n\nNew Year detected and folder created\n\n\n");

    CreateDirectory(decodyear, NULL);

//******Checks to see if day exists and creates new directory if statement if false*********\\ 

    sprintf(decodday, "c:\\temp\\PRN%3d\\Y%4d\\d%3d", decodPRN, year, day);
    SetCurrentDirectory(decodday); //sets directory to current day

    if (SetCurrentDirectory(decodday) == NULL)
        printf("\n\n\nNew Day detected and folder created\n\n\n");

    CreateDirectory(decodday, NULL);

//***************Creates new hourly file if none exists and opens for writing***************/

	SetCurrentDirectory(decodday);

    sprintf(decodday, "c:\\temp\\PRN%3d\\Y%4d\\d%3d\\h%2d.txt", decodPRN, year, day, hour);

	}
    //*************This portion writes the formatted data to the appropriate ems file************\\

   
	strcat(decoded, decodPRN);
    strcat(decoded, decoddate);
    strcat(decoded, decodtime);
    strcat(decoded, decodmsgtype);
    strcat(decoded, decodmsg);
    printf("String = %s\n", decoded);

    {
    FILE *fp = fopen(decodday, "a+b");

    if ((fp = fopen(decodday, "a+b")) == NULL)
        {
        printf("Cannot open file\n");
        fclose(fp);

        //*********Writes contents of decoded final data to the appropriate hour file********/

        fprintf(fp, "\n"); // should write to a new line	
        fputs(decoded, fp);

        //******************Closes the file and waits for next cycle*************************/

        fclose(fp);
        }

    return 0;
    }
}