C/C++ :: Program To Count Different Types Of Characters
Sep 24, 2014
My goal is to create a program that reads a string and counts how many Uppercase, Lowercase, Spaces, and digits there are in the string. Right now this the output i get.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main() {
int iochar;
char string;
4.1 Write a program that will count from 1 to 12 and print the count, and its square, for each count.
4.2 Write a program that counts from 1 to 12 and prints the count and its inversion to 5 decimal places for each count. This will require a floating point number.
4.3 Write a program that will count from 1 to 100 and print only those values between 32 and 39, one to a line. Use the incrementing operator for this program.
The code is supposed to convert characters from an array into their respective ascii integers, and append a 0 if the number is less than 3 digits long. It then supposed to put it all together into one string.
Code: #include <stdio.h> #include <string.h> #include <stdlib.h> int main(void){
char file[] = "This is a test"; char *ptr = file; int length = strlen(file); int i, numbers[length];
I have a upcoming C++ exam. I would like to write a program to convert INDIVIDUAL digits into words.
E.g 678 = six seven eight[/size][/b]
I have the following code:
//Program to print individual digits in words #include<iostream> using namespace std; int main() { int num; cout << "Enter a number between 0 and 9999: ";
I'm supposed to write a program to read a text file and display the following:
a) alphabetic letters //finished with b) digits // finished with c) other characters that are not alphabetic letters and not digits //finished with d) total characters read
The bold part above confused me, by total characters, does it mean the alphabetic letters + other characters? how would I put that in my code?
Code: #include <stdio.h> int main (void) { int curCh; int countCh = 0;
My problem is to count the characters in a file and define how many times each one occurs.Characters who are not found must not be included in the table; The output must be a table - like that -
”| character | ASCII- DEC | ASCI – HEX | how many times it occurs |”
This my function:
Code: int f2(FILE *p1) { FILE *g3; int char_count[256]={0}; char ch; int n=0; if(!(g3=fopen("D:zz.txt", "w"))){
[Code] ....
It must look like this: | D | 68 | 44 | 2 | | 2 | 50 | 32 | 1 | and so on...
The thing is, when I don't create a prototype of count and straightaway define it before void main() my program runs, but it gives error in this program that "extra parameter in call to count()" But what to do then?
I'm trying to create a program that counts the amount of alphabetical characters, numbers, blanks and total amount of characters in a string a user gets to enter. The user also quits the program manually by pressing CTRL + D (in linux terminal).
These are the results I get from the code so far by typing in "hello cplusplus 123 c++" CTRL + D.
The string had: Alphabetical characters...: 0 Numbers...................: 0 Blanks....................: 3 Total amount of characters: 20
So I can't seem to find a way to count the amount of alphabetical characters and numeric characters.
Here's my code:
#include <iostream> #include <string> #include <iomanip> #include <cctype> #include <sstream> using namespace std; int main() { string tecken;
[Code] ....
The reason why I declared cctype is that I think I should use the isalpha, isdigit and isblank functions but how I am supposed to do that.
int check_up(char string[]); int check_low(char string[]); void to_up(char string[]); void to_low(char string[]);
[Code] .....
When I compile this I have the following problems: warning: data definition has no type or storage class [enabled by default] in 'to_up(word)'conflicting types in 'to_up' function and to_low function warning: data definition has no type or storage class [enabled by default] into_up function error: unknown type name "word" in line 'printf("All uppercase %s. ", word):;'warning: parameter names (without types) in function declaration [enabled by default] in 'to_up(word)'and 'to_low(word)' 'note: previous declaration of "to_up" was here in function declaration of to_up function
I am trying to use enumeration types in my conditions to make a simple program that calculates area of a square or circle depending on users choice then updates the total area and outputs the total area.
The program builds fine. But it ignores all of my loop conditions and i'm not sure why.
I'm trying to develop a deeper knowledge of how loops work (and what better way todo that than a dynamic password guesser). My main problem lies with the conflict between data types, as I try to point to a char at a specific index position of the password guess.
See in my code (at line 57):
Code: #include <iostream> #include <iterator> #include <algorithm> #include <string> #include <cstdlib> #include <iomanip> using namespace std; string AlphaNum("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");//62 possible characters int size = AlphaNum.length();//should be 62
[Code] ....
This is annoying, because strings are arrays of characters themselves.
In class we were asked to create a C++ BTree program that would allow a user to input the following data types and then store said data in a .txt file:
0. ID 8 bytes
1. First name 30 char
2. Last Name 30 char
3. Street Address one 30 char
4. Street Adress two 30 char
5. City 30 char
6. State 20 char
7. Zip 10 char
8. Country 30 char
(I'm not particularly asking for full code, pseudo code would also be great). I had a great deal of my work done, unfortunately, the computer I was working on crashed, corrupting my files.
Write a C++ program that reads lines of text from a file using the ifstream getline() method, tokenizes the lines into words ("tokens") using strtok(), and keeps statistics on the data in the file. Your input and output file names will be supplied to your program on the command line, which you will access using argc and argv[].
You need to count the total number of words, the number of unique words, the count of each individual word, and the number of lines. Also, remember and print the longest and shortest words in the file. If there is a tie for longest or shortest word, you may resolve the tie in any consistent manner (e.g., use either the first one or the last one found, but use the same method for both longest and shortest).
You may assume the lines comprise words (contiguous lower-case letters [a-z]) separated by spaces, terminated with a period. You may ignore the possibility of other punctuation marks, including possessives or contractions, like in "Jim's house". Lines before the last one in the file will have a newline (' ') after the period. In your data files, omit the ' ' on the last line. You may assume that the lines will be no longer than 100 characters, the individual words will be no longer than 15 letters and there will be no more than 100 unique words in the file.
Read the lines from the input file, and echo-print them to the output file. After reaching end-of-file on the input file (or reading a line of length zero, which you should treat as the end of the input data), print the words with their occurrence counts, one word/count pair per line, and the collected statistics to the output file. You will also need to create other test files of your own. Also, your program must work correctly with an EMPTY input file – which has NO statistics.
Test file looks like this (exactly 4 lines, with NO NEWLINE on the last line):
the quick brown fox jumps over the lazy dog. now is the time for all good men to come to the aid of their party. all i want for christmas is my two front teeth. the quick brown fox jumps over a lazy dog.
Copy and paste this into a small file for one of your tests.
Hints: Use a 2-dimensional array of char, 100 rows by 16 columns (why not 15?), to hold the unique words, and a 1-dimensional array of ints with 100 elements to hold the associated counts. For each word, scan through the occupied lines in the array for a match (use strcmp()), and if you find a match, increment the associated count, otherwise (you got past the last word), add the word to the table and set its count to 1.
The separate longest word and the shortest word need to be saved off in their own C-strings. (Why can't you just keep a pointer to them in the tokenized data?)
Remember – put NO NEWLINE at the end of the last line, or your test for end-of-file might not work correctly. (This may cause the program to read a zero-length line before seeing end-of-file.)
Here is my solution:
#include<iostream> #include<iomanip> #include<fstream> using std::cout; using std::ifstream; using std::ofstream; using std::endl; using std::cin; using std::getline; void totalwordCount(ifstream&, ofstream&);
[Code] .....
Question: In the uniquewordCount() function, I am having trouble counting the total number of unique words and counting the number of occurrences of each word. In the shortestWord() and longestWord() function, I am having trouble printing the longest and shortest word in the file. In the countLines() function, I think I got that function correct, but it is not printing the total number of lines. Is there anything that I need to fix in those functions?
How we will write a program that will count a number of notes. I mean if i have 5676 rupees and i want to find the number of 5 thousand pak currency ,the number of 1000 notes, the number of 500 notes and the number of 100 notes. How we design such a program of if rlse structure to perform the above task.
My program does compile and counts the number of lines of code, which is LOC: 20. My issue this, according to my code instruction it should not count comments (//) and also shouldn't count blank lines of code. Unfortunately my code is counting // and white space.
What seems to be working is #, all three includes are not being counted. That’s a good sign. I’m using the same technique not to count #. Why isn't working for comments and blank lines? I’m pretty sure that my logic is correct. I think my problem is maybe syntax.
#include <iostream> #include <fstream> #include <string> using namespace std; int main() { //read my file
#include <stdio.h> /* function that will identify if line is empty or not */ is_empty(char *buffer) { while(isspace(*buffer)) buffer++; if(*buffer==0x00) return 1;
I have a .txt file that contains, together with a few characters, columns of values that I want to save in different files like is written in the program (file 1, file2, file3 - a with x, b with y, c with z). The pattern of the source text file is like this:
Until now I could manage to split the files, but the output gives me only zeros. First the program count the number of lines of the read text file, then it should display the desired columns of double values in three other .txt files.I've got for the three .txt files columns like this:
I'm making some progress. My program does compile and output the number of line per code, but it shouldn't count comments and blank lines. I tried using (s.substr(0,2) == "//") as suggested but it didn't work.
This is my improved code:
Code: #include <iostream> #include <fstream> #include <string> using namespace std; const int A = 3; int main() { string s;
I tested my count funtion. So my count function is not working properly, it should return 5 because 5 words have prefix "tal," but it is giving me 10. It's counting blank nodes.
This is my main.cpp file
int main() { string word; cout<<"Enter a word"<<endl; cin >> word; string filename;