Input is not making sense

0
void cadastroturma () {
char turma[30],caminho[100];
printf ("Diga o nome da turma a ser cadastrado:\n");
scanf ("%[^\n]", &turma);//Já tentei com gets e fgets
getchar();//Já tentei sem esse getchar
printf ("\nAgora o caminho onde quer gravar a turma:\n");
scanf ("%[^\n]", &caminho);
getchar();
mkdir(caminho);
strcat(strcat(strcat(caminho,"/"),turma),".coe");
printf("%s", caminho);
FILE *cadastro = fopen (caminho, "ab");

Hello, I am doing a job in the faculty of archiving, this is the function of class registration, I have not yet put the number of students but this is not the point ... The problem is that in the output, in so many ways that I have already put it, the file created inside the folder either goes unnamed before the extension or is not created in any way. I've even tried it with the infamous gets () function and it did not work. What I want to do is enter the class name, then the folder name, create the folder and then join the names to create the file inside the folder. Can anyone help me?

    
asked by anonymous 11.12.2017 / 12:01

2 answers

0

You missed the end

strcat(strcat(strcat(caminho,"/"),turma),".coe");
printf("%s", caminho);
FILE *cadastro = fopen (caminho, "ab");

should look like this:

FILE *cadastro = fopen (strcat(strcat(strcat(caminho,"/"),turma),".coe"), "ab");

or by placing within the variable

strcpy(caminho, (strcat(strcat(strcat(caminho,"/"),turma),".coe"));
    
11.12.2017 / 12:38
0

Dude, maybe instead of concatenating the name, you pass the variable with the directory name, and the file as a parameter to create it would be simpler.

    
11.12.2017 / 14:16