I want to open a file with the title e.g. "File 10-9B-g06.dat" where "B" and "File" are repeated for all files but the rest are variable. The problem start when I have the "g" in the title. I used the "g" variable as a string, but it did not work as well.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int CaseSize, Type, Counter;
char name[100], zahl[20], char Template[1];
FILE *stream;
scanf("%d", &CaseSize );
scanf("%d", &Type );
scanf(" %c", &Template );
scanf("%d", &Counter );
strcpy(name, "File ");
sprintf(zahl, "%d", CaseSize);
strcat(name, zahl);
strcat(name, "-");
sprintf(zahl, "%d", Type);
strcat(name, zahl);
strcat(name, "B-");
sprintf(name, "%c", Template);
strcat(name, zahl);
sprintf(zahl, "%2d", Counter);
strcat(name, zahl);
strcat(name, ".dat");
stream=fopen(name, "a");
fclose(stream);
return 0;
}
I was wondering if anyone can help explain this to me or if they can direct me to anywhere I can get some examples I can look through.
Thanks.