Created
March 7, 2015 01:16
-
-
Save WilliamHester/365dc64b0f2eeada029a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#define EXIT_SUCCESS (0) | |
int main(int argc, char const *argv[]) | |
{ | |
/*Develop Variables*/ | |
FILE *inp; /*file pointer*/ | |
int status; /*fscanf feed back*/ | |
int i = 0; /*counter variable*/ | |
const char *word = argv[2]; /*word found*/ | |
int wordc; /*word count*/ | |
/*check number of argument in command line*/ | |
if (argc < 2) | |
{ /*when arguments < 2 are stated*/ | |
printf ("EE 233 Spring 2015 P4,Toneyah,Toney A. Hicks"); | |
return -1; | |
// exit(0); | |
} | |
else | |
{ | |
/*attempt to open file specified*/ | |
inp = fopen (argv[1], "r"); | |
/*if file does not open, error*/ | |
if(inp == NULL) | |
{ | |
printf("Could not open file. Will close\n"); | |
return -1; | |
} | |
else | |
{ | |
char string[81]; // the string that we're going to read in | |
// guaranteed to have <= 80 characters | |
if (fgets(string, 81, inp) != NULL) | |
{ // We're good to go. | |
int wordLength = strlen(word); | |
for (int j = 0; j < 81 - wordLength; j++) | |
{ | |
int k; | |
for (k = 0; k < wordLength; k++) | |
{ | |
if (string[j + k] != word[k]) | |
{ | |
break; | |
} | |
} | |
if (k == wordLength) | |
{ | |
// We found an occurance of the specified word | |
i++; | |
} | |
} | |
} | |
printf("%d\n", i); | |
} | |
} | |
return (EXIT_SUCCESS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment