FSaraiva Posted October 28, 2009 at 09:50 PM Report Share #293777 Posted October 28, 2009 at 09:50 PM 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 More sharing options...
Solution Baderous Posted October 29, 2009 at 04:28 PM Solution Report Share #293877 Posted October 29, 2009 at 04:28 PM #include <stdio.h> #include <string.h> int main(void) { char nome[5]="TMD "; FILE *fp = NULL; int i; for (i=1;i<=3;i++) { nome[3]=i+'0'; fp = fopen(nome,"w"); fclose(fp); } return 0; } Link to comment Share on other sites More sharing options...
FSaraiva Posted October 29, 2009 at 05:57 PM Author Report Share #293891 Posted October 29, 2009 at 05:57 PM Muito Obrigado era mesmo isso. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now