/* Print the word and the number of counts to file if file opens or to
 * screen if opening of file fails.
 * @param map counts the map of all the counts
 * */
void output(count_map pCounts) {
//  Output duplicates to a file
    count_iter the{pCounts.find("the")};
    const int count_size{10};
    std::ofstream out{"ExploreOut.txt"};
    if (not out) {
        std::perror("ExploreOut.txt");
        found(the, pCounts);
        for (auto element : pCounts)
            std::cout << std::setw(longest_word(pCounts)) << std::left << element.first
                      << std::setw(count_size) << std::right << element.second << '\n';
    }
    else {
        std::cout << "Written to file\n";
        found(the, pCounts);
        for (auto element : pCounts)
            out << std::setw(longest_word(pCounts)) << std::left << element.first
                << std::setw(count_size) << std::right << element.second << '\n';
        out.close();
    }
}
Example #2
0
int main()
{
    printf("Enter text\n");
    char *line = line_reading(BUFFER);

    char *longestWord = longest_word(line);
    printf("Longest word -> %s", longestWord);

    free(line);
    free(longestWord);

    return (EXIT_SUCCESS);
}
Example #3
0
File: term.c Project: Zethir/42sh
void		win_select_size(int id)
{
	t_struct		*info;
	struct winsize	win;

	(void)id;
	info = NULL;
	info = stock_select_struct(info, 1);
	ioctl(0, TIOCGWINSZ, &win);
	info->col = win.ws_col;
	info->row = win.ws_row;
	longest_word(info);
	info->nb_item = (info->node->length) / info->nb_col;
	if (((info->node->length) % info->nb_col) != 0)
		info->nb_item += 1;
	check_size(info);
}
Example #4
0
int main(int argc, char **argv)
{
	if (argc != 2)
	{
		printf("usage: %s %s\n", argv[0], "filename");
		return 0;
	}
	FILE *file = fopen(argv[1], "r+");
	if (!file)
	{
		perror("Could not open file.\n");
		return 1;
	}
	insert_newline(file);
	char line[200] = "";
	while (fgets(line, 200, file) && !feof(file))
	{
		longest_word(line);
	}
	fclose(file);
	return 0;
}