Aller au contenu
View in the app

A better way to browse. Learn more.

Next

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[C++]Donner un nom consécutif à des fichiers.

Featured Replies

Posté(e)

Voila en gros pour résumer vite fait ça ressemble à ça :

#include <stdio.h>
int main()
{
   int i = 1;
   int j = 10;

   while(i < j) {
       FILE *pfile = fopen (i, "wt");
       fclose(pfile);
       ++i
   }
   return 0;
}

Sauf que j'ai ça comme erreur : cannot convert parameter 1 from 'int' to 'constchar *'.

Ok j'ai bien compris pourquoi mais j'aimerais savoir s'il y a moyen d'y remédier...

Et au final on obtiendrais dans le repertoir c: des fichiers texte allant de 0.txt jusqu'à 10.txt.

Merci d'avance.

Modifié par X-Kalibur

Posté(e)
  • Auteur

De toute façon même si c'est possible ça m'interraisse pas, vu que je veux pas transformer "i" en un "const char*" car si elle devient une constante les fichiers ne pouront plus changer de noms.

Posté(e)

Si tu convertis les entiers grâce à sprintf(), ça devrait passer.

#include <stdio.h>
int main()
{
  int i = 1;
  int j = 10;
  char tmp[256];

  while(i < j) {
      sprintf(tmp,"%d",i);
      FILE *pfile = fopen (tmp, "wt");
      fclose(pfile);
      ++i
  }
  return 0;
}

Mmmh par contre je viens de me réveiller donc... :incline:

Posté(e)

#include <stdio.h>
#include <string.h>
int main()
{
  int i = 1;
  int j = 10;
  char tmp[256];

  while(i < j) {
     sprintf(tmp,"%d",i);
     strcat(tmp, ".txt");
     FILE *pfile = fopen(tmp, "wt");
     fclose(pfile);
     ++i;
  }
  return 0;
}

avec un petit strcat (string.h :francais:) pour ajouter le suffixe .txt

edit: houla... à croire que je veux voir des string(.h) partout :incline:

sprintf(tmp,"%d.txt",i) c'est pas mal aussi... :mdr:

---> []

Modifié par astero-H

Archivé

Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.