Jump to content

Criar ficheiros com nomes diferents(Problema no incremento)


FSaraiva
 Share

Go to solution Solved by Baderous,

Recommended Posts

Boa noite.

Devido a estar a horas com um exercicio simples decidi postar a minha duvida.

Exercicio: Alterar este código de modo que o nome dos ficheiros criados passem de TPM+pid para TPM1 ou TPM2 até  TPM9.

#include <stdio.h>
main (){
FILE *fd;
char nome[15] ;
fork();
fork();
fork();
sprintf(nome, "TMP%d", getpid());
fd = fopen (nome, "w");
fclose(fd);
}

tentei solucionar o problema com uma variavel static que ia incrementando á medida que criava os ficheiros mas só consigo na situaçao TMP1 de resto nem chega a criar.

Agradecia que me pudessem ajudar.

Melhores cumprimentos.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.