SHARE
TWEET

Untitled

a guest Sep 17th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * Student: Tjeerd Bakker
  3. * Number: S2097966
  4. * Assignment: 4.8
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10.  
  11. int main(int argc, char *argv[])
  12. {
  13.     char a[1024];
  14.     int i;
  15.     int total = 0;
  16.     if(argc == 1) /*argc = 1 (filename) + number of arguments. If argc==1, then only the filename has been passed, no extra arguments*/
  17.     {
  18.         printf("No argument given\n");
  19.         return 0;
  20.     }
  21.  
  22.     while(1){
  23.         memset(a, 0, sizeof(a)*sizeof(char));
  24.         fgets(a, 1024 , stdin);
  25.         if(strncmp(a,"#EOF",4) == 0)
  26.         {
  27.             break;
  28.         }
  29.         for(i = 0; i < (1023 - strlen(argv[1])); i++)
  30.         {
  31.             if(strncmp(argv[1], a + i, strlen(argv[1])) == 0)
  32.             {
  33.                 total++;
  34.             }
  35.         }
  36.     }
  37.     printf("%d\n",total);
  38.  
  39.     return 0;
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top