Advertisement
Guest User

primzahltest

a guest
Oct 26th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "Eratosthenes.h"
  5.  
  6. #define OBERGRENZE_MIN 3
  7. #define OBERGRENZE_MAX 20000
  8.  
  9. #pragma warning (disable : 4996)
  10.  
  11. void Hilfetext(void);
  12.  
  13. int main (int argc, char *argv[])
  14. {
  15.     int intErfolg = EXIT_FAILURE;
  16.     int intEingabe = -1;
  17.  
  18.     if (2 != argc)
  19.     {
  20.         printf("\nFehler1:Unerwartete Anzahl an Parameter");
  21.         Hilfetext();
  22.     }
  23.     else if(strcmp(argv[1], "help")) //wie ging das nochmal?
  24.     {
  25.         Hilfetext();
  26.     }
  27.  
  28.     else if (1 != sscanf(argv[1] , "%d", &intEingabe))
  29.     {
  30.         printf("\nFehler2: Parameter keine Zahl!");
  31.         Hilfetext();
  32.     }
  33.     else if(intEingabe>OBERGRENZE_MAX)
  34.     {
  35.         printf("\nFehler3: Der Parameter zu gross.\n\n");
  36.         Hilfetext();
  37.  
  38.     }
  39.     else if(intEingabe<OBERGRENZE_MIN)
  40.     {
  41.         printf("\nFehler4: Der Parameter ist kleiner gleich 2.\n\n");
  42.         Hilfetext();
  43.     }
  44.     else if((1 == sscanf(argv[1] , "%d", &intEingabe))&&(intEingabe<=OBERGRENZE_MAX)&&(intEingabe>=OBERGRENZE_MIN))
  45.     {
  46.         int i = 0;
  47.         unsigned int arrPrim[OBERGRENZE_MAX] = {0};
  48.         printf("\nIhre Eingabe: %d\n\n", intEingabe);
  49.        
  50.         for (i=2 ; i <=intEingabe; i++)
  51.         {
  52.            
  53.             printf("%d", arrPrim[i]);
  54.         }
  55.  
  56.         intErfolg = EXIT_SUCCESS;
  57.     }
  58.     else
  59.     {
  60.         printf("Fehler 5: Dieser Fall sollte nicht eintreten");
  61.         Hilfetext();
  62.     }
  63.     return intErfolg;
  64.  
  65. }
  66.  
  67. void Hilfetext(void)
  68. {
  69.     printf("\n\t Aufruf: SiebDesEratosthenes.exe Obergrenze\n\n");
  70.     printf("\t\t mit 2 < Obergrenze <= 20000\n");
  71.     printf("\tDas Programm erwartet als Parameter auf der Kommadozeile\n\teine natuerliche nichtnegative Zahl.\n");
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement