Input is not making sense

Asked

Viewed 63 times

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 work of the faculty of archive, this is the function of register of class, I have not put the board of students but this is not the point... The problem is that in the output, in so many ways that I have already put, the file created inside the folder either goes unnamed before the extension or is not created at all. I’ve tried even with the infamous gets() function and it didn’t work. What I want to do is enter the name of the class, then the name of the folder, create the folder and then merge the names to create the file inside the folder. Can someone help me?

2 answers

0

you missed in the end

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

it should be like this:

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

or placing inside the variable

strcpy(caminho, (strcat(strcat(strcat(caminho,"/"),turma),".coe"));
  • The file has to be binary, no need to put the b at the end no? Anyway thanks even for the help.

  • yes you need the b in the end

0

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

  • What do you mean? In the syntax I studied I found no loophole for this, but you mean put as (way"/"class". Coe", "ab") ?

  • That way I put it didn’t work... so the problem isn’t exactly this, is that when entering with the data, all printfs appear before and the file inside the folder was not created with the name I asked, only the extension. Now, with the fix I made the file is not even created...

  • Face say like this: path = strcat(strcat(path,"/"),class),". Coe"); FILE *registration = fopen (path, "ab");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.