
Points to consider:
Code
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<omp.h>
int main(){
//double start_time = omp_get_wtime();
char str[1000];
int freq[26];
int ch;
int i;
FILE* file;
printf("The frequencies are: \n");
for(i = 0;i<26;i++){
freq[i] = 0;
}
int file_index = 1;
char file_name[] = "0.txt";
if((file = fopen(file_name, "r") == NULL)){
printf("error");
exit(1);
}
while(file_index<=9){
file_name[0] = (char)('0' +
file_index);
if(file = fopen(file_name, "r") ==
NULL){
printf("error");
exit(1);
}
while(fgets(str,
sizeof(str), file) != NULL){
ch =
strlen(str);
for(i =
0;i<ch;i++){
if(str[i] >= 'a' && str[i] <=
'z'){
freq[str[i] - 97]++;
}else if(str[i] >= 'A' && str[i]
<= 'Z'){
freq[str[i]-65]++;
}
}
}
file_index += 1;
}
for(i = 0;i<26;i++){
if(freq[i] != 0){
printf("%c's:
%d\n'", (i+65, freq[i]));
}
}
}
That was a nice
question to answer
Friend, If you have any doubts in understanding do let me know in
the comment section. I will be happy to help you further.
Thanks
How do i write a program to read muliple files? i can read one but i...
Below is my c++ code. For the first section how do I include multiple text files such as file8, file 25, file 50, file 125? Also, for algorithm 1 my clock function does not work. I need it to start the clock before the algorithm then run through it and record the end time. Then find the difference between end time and start time and convert it to milliseconds. The print out the max sum and the run time!!!! Im...
I am having problems with the following assignment. It is done
in the c language. The code is not reading the a.txt file. The
instructions are in the picture below and so is my code. It should
read the a.txt file and print. The red car hit the blue car and
name how many times those words appeared. Can i please get some
help. Thank you.
MY CODE:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node {
char *str;
int...
C++ Can someone please help me with this problem- commenting each line of code so I can understand how to solve this problem using the C++ programming language? I really need help understanding how to create a file for the program to read. Do I create the file in Visual basic or create a text file? I have the code, just need to know how to create the file for it to read. #include<fstream> #include<iostream> using namespace std; int main()...
Writing a program in C please help!! My file worked fine before but when I put the functions in their own files and made a header file the diplayadj() funtion no longer works properly. It will only print the vertices instead of both the vertices and the adjacent like below. example input form commnd line file: A B B C E X C D A C The directed edges in this example are: A can go to both B and...
Use two files for this lab: your C program file, and a separate text file containing the integer data values to process. Use a while loop to read one data value each time until all values in the file have been read, and you should design your program so that your while loop can handle a file of any size. You may assume that there are no more than 50 data values in the file. Save each value read from...
Please write MIPS program that runs in QtSpim (ex: MipsFile.s) Write a MIPS program that will read in a base (as an integer) and a value (nonnegative integer but as an ASCII string) in that base and print out the decimal value; you must implement a function (which accepts a base and an address for a string as parameters, and returns the value) and call the function from the main program. The base will be given in decimal and will...
Write a complete C program that inputs a paragraph of text and prints out each unique letter found in the text along with the number of times it occurred. A sample run of the program is given below. You should input your text from a data file specified on the command line. Your output should be formatted and presented exactly like the sample run (i.e. alphabetized with the exact spacings and output labels). The name of your data file along...
Write a program that replace repeated three characters in a string by the character followed by 3. For example, the string aabccccaaabbbbcc would become aabc3ca3b3cc. When there are more than three repeated characters, the first three characters will be replaced by the character followed by 3. You can assume the string has only lowercase letters (a-z). Your program should include the following function: void replace(char *str, char *replaced); Your program should include the following function: void replace(char *str, char *replaced);...
It is a C++ program by using
inheritance and vectors
My professor said that all the files should be separate. like
File.cpp, File.h, Text.cpp,Text.h,Main.cpp
I already have these files
File.cpp
#include "File.h"
// Constructor of File that takes File name and type as
arguments
File::File(string type, string name) {
this->type = type;
this->name = name;
}
//returns the type.
string File::getType() {
return type;
}
//returns the name of file.
string File::getName() {
return name;
}
File.h
#ifndef __FILE_H__
#define...
Write a C++ program to display workers schedule for a company. To accomplish this (1) Write a struct Time with attributes (at least) : hours, minutes and seconds. Add other functions or attributes you need to get the job done (2) Write a class Schedule with attributes : Day of week, start_time, end_time and activity. Schedule should have at least (a) Display to display the schedule (b) Length to return the duration of the schedule (ie end_time - start_time), (c)...