Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

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.

Empfohlene Antworten

Veröffentlicht

HI

ich habe folgendes Probel und hoffen, das mir einer helfen kann. Ich schreibe gerade an einem Programm, welches Verzeichnisse aufraeumen soll. Das das ganze auf einem Linux System basiert will ich "rm -f" benutzen. zur besseren Verständnis ist hier das Programm:


#include <stdio.h> 

#include <ctype.h> 

#include <stdlib.h> 

#define __USE_GNU 

#include <string.h> 

#undef __USE_GNU 

#include <sys/types.h> 

#include <sys/stat.h> 

#include <time.h> 

#include <dirent.h>  

#define DEBUG 1 

#define EXIT_FAILURE 1

#define EXIT_SUCCESS 0 

#define DELETE_FILE(fileName)  printf("rm -f "fileName"")  


int testDir(char *dirname, char myDZG[11]); 


int main() {   

  int retVal=-1;

  char DZG[11];

  struct tm *l_time;


  time_t now;

  now = time((time_t *)NULL);

  time(&now);

  l_time = localtime(&now);

  strftime(DZG, sizeof DZG, "%Y%m%d\n", l_time);

  printf("DZG: %s\n",DZG);

  retVal=testDir("/home/webokan/wkn/bin/avigen/", DZG);

  return EXIT_SUCCESS ; 

}


int testDir(char *dirname, char myDZG[11]) {

  DIR *myDir;

  char *fileDZG;

  char *tmp;

  int  dzgDiff;

  char myPath[255];

  char *fileName;

  struct dirent *myFiles;

  if ((myDir=opendir(dirname)) != NULL) {

    while((myFiles=readdir(myDir))!=NULL) {

      if((tmp=strstr((*myFiles).d_name,"200"))){

        fileDZG=strndup(tmp,8);

        dzgDiff=atoi(myDZG)-atoi(fileDZG);

        fileName=(char *)(*myFiles).d_name;

        strcpy(myPath,dirname);

        strcat((char *)myPath,(char *)fileName);

        printf("DATNAME: %s\n",fileName);

        printf("DATNAME2: %s\n",myPath);

        if(dzgDiff>700){

         DELETE_FILE(\"myPath\");


        }

        #ifdef DEBUG

          printf("TMP: %s\n",tmp);

          printf("File: %s\n",(*myFiles).d_name);

          printf("DZG:  %s\n",myDZG);

          printf("FDZG: %s\n",fileDZG);

          printf("DIFF: %d\n",dzgDiff);

 //       printf("PATH: %s\n",myPath);

        #endif

        free(fileDZG);

      }


    }

  } else {

    printf("Fehler beim öffnen des Verzeichnisses");

    return EXIT_FAILURE;

  }

  if(closedir(myDir) == -1) {

    printf("Fehler beim Schliessen von %s\n", dirname);

  } else {

    return EXIT_FAILURE;

  }

  return EXIT_SUCCESS;

}

 

Ich bastel mir also den komplette Pfad zusammen, in dem die Datei liegt und lege Ihn in der Variablen myPath ab. Nun möchte ich den Inhalt von myPath über das define DELETE_FILES erstmal in den printf Befehl geben. Kann auch sein, das es nur ein quoting Fehler ist ?

Wäre super, wenn Ihr da helfen könnt.

Gruß Cooper83

Das funktioniert so nicht. Der Präprozessor kann dir nur Strings zusammenfügen, die bereits fest im Quellcode stehen, da er zur Compilezeit aktiv wird. Du willst eine Variable einfügen, die erst zur Laufzeit mit Inhalt gefüllt wird.

Du wirst nicht um sprintf & Co. herumkommen. Das kannst du zwar auch in ein Makro verpacken, aber davon rate ich ab. Schreib besser eine Funktion dafür.

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

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.