Advertisement
m027

SearchLetter

Jan 6th, 2021
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. int main()
  5. {
  6.  
  7.     char string[254];
  8.     char letter;
  9.     int i;
  10.     int count = 0;
  11.        
  12.  
  13.     printf("Gib einen Satz an: \n");
  14.     fgets(string, sizeof(string), stdin);
  15.  
  16.     printf("Welcher Buchstabe soll gesucht werden?\n");
  17.     scanf("%c", &letter);
  18.  
  19.     for( i = 0; string[i] != '\0'; i++ )
  20.     {
  21.         if( string[i] == letter)
  22.         {
  23.             count++;
  24.         }
  25.  
  26.     }
  27.  
  28.     printf("Der Buchstabe %c kommt %d mal vor\n", letter, count );
  29.  
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement