fork(2) download
  1. #include <stdio.h>
  2. #pragma warning(disable : 4996)
  3.  
  4. int main(void)
  5. {
  6. char str[10];
  7. const char str2[] = "Teststring"; // in C: 0-terminierter String
  8. int i = 0; // Laufvariable
  9. int anzZahlen = 0;
  10.  
  11. printf("Geben Sie einen String ein: ");
  12. //scanf("%s", str);
  13. fgets(str, 10, stdin);
  14. printf("\nString: %s", str);
  15.  
  16. // siehe ASCII-Tabelle: https://d...content-available-to-author-only...a.org/wiki/American_Standard_Code_for_Information_Interchange#ASCII-Tabelle
  17. while (str[i] != 0) // Integer 0 entspricht char '\0'
  18. {
  19. //if (str[i] >= '0' && str[i] <= '9') // Zeichen aus ASCII-Tabelle
  20. //if (str[i] >= 48 && str[i] <= 57) // Dezimale-Werte aus ASCII-Tabelle
  21. //if (str[i] >= 060 && str[i] <= 071) // Oktal-Werte mit führender 0
  22. if (str[i] >= 0x30 && str[i] <= 0x39) // Hex-Werte
  23. anzZahlen++;
  24. i++; // Laufvariable erhöhen
  25. }
  26.  
  27. printf("Anzahl Zahlen= %d", anzZahlen);
  28.  
  29. fflush(stdin); // Tastaturpuffer löschen
  30. getchar(); // Warte auf Enter-Taste
  31.  
  32. }
Success #stdin #stdout 0s 10304KB
stdin
ABC123AA
stdout
Geben Sie einen String ein: 
String: ABC123AAAnzahl Zahlen= 3