Tabstop, thank you very much for you help. I've finished my program and it works a treat. I've put the code below if anyone ever wants it in the future.
Code:
#include <stdio.h>
#include <string.h>
#include <errno.h>
#define EXTENSION ".txt"
int main ( int argc, char **argv )
{
int count=0;
char fileName[100];
char TempfileName[100];
char TempString[256];
char TempChar;
FILE *fp;
FILE *fpTmp;
fp = fopen(argv[1], "rb");
if(fp == NULL)
{
/*fprintf(stderr, "Error Opening File: %s\n", fileName); */
printf("Error Opening File %s: %s", argv[1], strerror(errno));
return -1;
}
else
printf("%s Opened Successfully.\n\n\n",argv[1]);
while(!feof(fp))
{
for(count=0; ( (TempfileName[count] = fgetc(fp)) != ',' ) ; count++);
TempfileName[count] = '\0';
strcat(TempfileName,EXTENSION);
chdir("split"); /* split is the sub directory, change to another if wanted */
fpTmp = fopen(TempfileName,"ab");
if(fpTmp == NULL)
{
fprintf(stderr, "Error Opening File: %s\n", TempfileName);
return -1;
}
else
printf("%s Opened Successfully.\n",TempfileName);
fgets(TempString,256,fp);
TempString[strlen(TempString)-1] = '\n';
fputs(TempString, fpTmp);
printf("%sWritten to %s\n", TempString, TempfileName);
fclose(fpTmp);
printf("%s Closed.\n\n",TempfileName);
}
}