Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication4.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include "pch.h"
- #include <iostream>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #define MAX_WORD_LENGTH 100
- int main()
- {
- FILE *fptr;
- int argc;
- char filename[15];
- char str[60];
- char *largest = (char*)malloc(MAX_WORD_LENGTH);
- char *smallest = (char*)malloc(MAX_WORD_LENGTH);
- int smallest_len = MAX_WORD_LENGTH, largest_len = 0;
- printf("Enter the file name you want to open:\n");
- scanf("%s", filename);
- fptr = fopen(filename, "r");
- if (fptr == NULL)
- {
- printf("Cannot open file \n");
- exit(0);
- }
- while (fgets(str, 60, fptr) != NULL)
- {
- char *temp = strtok(str, " ");
- while (temp != NULL)
- {
- if (strlen(temp) > largest_len)
- {
- strcpy(largest, temp);
- largest_len = strlen(largest);
- }
- temp = strtok(NULL, " ");
- }
- }
- printf("The largest word in the file is: %s\n", largest);
- fclose(fptr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement