Tuesday, November 6, 2018

day 21 lab

/*??????????????????????????????????????????????????????????????-*/
/* This program initializes a long character string and a short */
/* character string. It then prints the locations of the short */
/* string in the long string. It also prints the number of */
/* occurrences of the short string in the long string. */
#include <stdio.h>
#include <string.h>
#define FILENAME "longstring.txt"
int main(void)
{
FILE *in_file = fopen(FILENAME, "r"); //read the textfile
/* Declare and initialize variables. */
int count=0;
char short_str[3],
c = fgetc(in_file);
/* Print Short String. */
printf("Enter the short_string\n");
scanf("%s", short_str);
if (in_file == NULL)//open file
{

printf("cannot open file \n");
}
printf("Your shortstring: %s\n", short_str);
/*Read data from file*/
c = fgetc(in_file);
while(c > 0)
{
printf ("%c", c);
c = fgetc(in_file);
}
fclose(in_file);
/* Exit program. */
return 0;
}

/*????????????????????????????????????????????????????????????-*/

No comments:

Post a Comment