C/C++ :: Calculating Entropy Of A File - Expected Expression And Too Few Arguments
Sep 22, 2014
It's been awhile since I've coded in C. I'm picking it back up to get some practice. I'm going through my old programs from a few years ago, and I ran into one where I'm calculating the entropy of a file. The problem I'm having is that everytime the program runs, no matter what file I choose for it to calculate the entropy on, it gives 3.00000 as a result. I've gone through it and can't seem to figure out why it's possible doing that.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define SIZE 256
int entropy_calc(long byte_count[], int length) {
float entropy;
float count;
[Code] .....
View 5 Replies
ADVERTISEMENT
Mar 29, 2014
I keep getting an error here and cant quite figure out why,
Code:
else if (mainMenu == 3){
cout << "Please make a selection" << endl
<< " 1) Withdraw from account" << endl
<< " 3) Back to main menu" << endl;
cin >> withdrawMenu;
if (withdrawMenu == 1){
[Code] ....
View 1 Replies
View Related
Jun 18, 2014
I wrote a program, that generates 20 random integers, and stores them in an array. Then I decided, to build more functions to it, i.e why not have it to display the lowest integer of an array. I created my function,
Code:
int minValue( int field[ ] )
and got my code in side, which (technically) works. In my main() function I'm calling
Code:
printf( "The smallest value of an array is: %d
", minValue( field[] ) );
and I'm getting an error trying to compile it.
Code:
randomArray.c:62:74: error: expected expression before ']' token
printf( "The smallest value of an array is: %d
", minValue( field[] ) );
View 2 Replies
View Related
May 26, 2014
This is what i have example code in c++:
#include <iostream>
class Foo{
public:
void bar(){
std::cout << "Hello" << std::endl;
[Code] ....
After compiling it is giving error as :
foo.cpp: In function ‘int Foo_max(Foo*)’:
foo.cpp:26:37: error: expected primary-expression before ‘int’
foo.cpp:26:46: error: expected primary-expression before ‘int’
View 6 Replies
View Related
Sep 10, 2013
I'm pretty new to C, and keep getting an error. Basically I'm trying to convert a ppm image to all red. Here is my code that I can't get to work:
Code:
change(pixel_t *PIXEL, &w, &h,pixel_t *buffer);
And here is the beginning of my convert function:
Code:
void change(pixel_t *pixel, int w, int h, pixel_t *buffer) {
int average, sum;
int i;
pixel_t *pointer;
Everything else works fine. I keep getting an error when I call the convert function. It says "expected expression before pixel_t" and "too few arguments to function "change". I know that everything else in the main is working.
View 3 Replies
View Related
Apr 23, 2014
This is my code so far and in my else if statements its sayin "Expected Primary Expression Before "Else"
What do i do?
#include <iostream>
using namespace std;
int main () {
//declare variable
double n,a,b,c,d,total;
[Code] ....
View 3 Replies
View Related
Sep 12, 2013
work out this error?
guidedTour.cpp: In constructor 'GuidedTour::GuidedTour(std::string, std::string, double, double, Date, double, std::string)':
guidedTour.cpp:4: error: expected primary-expression before 'id'
guidedTour.cpp:4: error: expected primary-expression before 'description'
guidedTour.cpp:4: error: expected primary-expression before 'double'
guidedTour.cpp:4: error: expected primary-expression before 'double'
// SOURCE
#include "guidedTour.h"
[code]....
View 2 Replies
View Related
May 30, 2014
Trying to write a function, Even, that will tell you the total amount of even numbers in the array
#include <iostream>
using namespace std;
const int MAX_ROWS = 3;
const int MAX_COLUMNS = 2;
int Even(int A[int length][int width], int length, int width) {
[Code] ....
View 1 Replies
View Related
Jan 22, 2014
How do to calculate the following equation"5+((56+8)/2)" using expression builder
Note: the equation may change "50+((26+8)/12)"
View 1 Replies
View Related
Jul 9, 2013
Ok, I got everything else to work in a two part exercise except for the 2nd part.
The first part had me take up to 20 grades, calculate total, average, and then list the grades with a '*' next to ones that were lower than the average... good to go.
Now in the 2nd part of the exercise I have to also associate a letter grade with the grades in the list. I have done a "if else" chain, but am having an issue with multiple arguments and not sure if I have gone the right route.
Code:
//Cameron Taylor
#include <stdio.h>
#include <math.h>
#define MAXARRAY 20
[Code].....
View 9 Replies
View Related
Mar 21, 2014
Here's my attempt:
input.open(name);
if (input.fail()){
cout <<"Error opening file"<<endl;
}
while (input>>numbers)
{
counter++;
total += numbers;
[Code]...
Copy of the output:
Error opening file
The Standard Deviation of all the numbers is: -9.25596e+061
Press any key to continue . . .
Its not giving me the right answer.
View 1 Replies
View Related
Feb 19, 2015
I have the following code. Everything compiles but when it runs the sums are not correct. I need to calculate the sums for all the odd integers, the even integers, and all the integers.
my infile was provided with the following integers. I am not supposed to assume the infile has 20 integers.
Also, I wanted to the average to calculate with two decimal place precision and that is also incorrect??? setprecision(2) I thought would work???
#include <cstdlib>
#include <iostream>
#include <fstream>
[Code]......
View 4 Replies
View Related
Mar 14, 2014
I have an EDI file whose structure is given below. This file has multiple records, each record contains a header (e.g EDI.DD.0000000001.20130809), then contents (i.e multiple paragraphs of text) and then footer (e.g End of Report/No EDI Activity). I have to read that entire file using regular expression using three groups.
I am using following regular expression to read the file.
(?<header>[A-Z]{3}.[A-Z]{2}.[0-9]{10}.[0-9]{8}) | (?<footer> (EndsofsReport|NosEDIsActivity)) |
(?<content>(?<=k<header>).*(?=k<footer>))
That expression reads the "header" and "footer" in respective groups properly but didn't pick the contents between header and footer in "contents" group.
I have changed the font of header and footer in below file to understand the format. I am using asp.net 3.5 framework.
//------------------Start of EDI File---------------------//
EDI.DD.0000000001.20130809
ORIGINATOR INFORMATION Company Name: UNITED HEALTHCAR Identification: 9024125001 Originating DFI: 002100002
RECEIVER INFORMATION Receiver Name: HEALTH & WELLNESS DFI Account Number: 0000000000000001 Receiving DFI ID: 434343430 ID Number: Transaction Type: 22 Deposit
ORIGINATOR INFORMATION Company Nam
[Code] ....
View 1 Replies
View Related
Apr 9, 2012
I am trying to use the command line to put a txt file in this code. I do Project->set project arguments in code blocks and nothing happens. How does one set up the arguments and where do i do it in codeblocks?
Code:
int main(int argc, char *argv[]) {
char name[20];
struct artist *ptr;
char lineBuffer[LINEBUFFERSIZE];
artistNodePtr startPtr = NULL; /* initially the artist list is empty */
FILE *musicFile;
char *artistTemp, *discTemp, *yearTemp, *trackTemp, *songTemp;
[Code] ....
View 2 Replies
View Related
Mar 10, 2013
Actually the below program is for Dispersal Algorithm called Rabin-IDA; this algorithm divided the data into N pieces and then recombine it from M pieces (such that M<N).
Thus, the below program needs command line arguments,which entering by Project properties/Debugging. this argument is file name, where the program performing spitted the file into N files, and then recombine it from M divided files, and put it on another file which should also passing its name as argument .
Now my question is, How can i make this program enter the file name by keyboard??(i mean enter the files name by user from screen not as command line arguments) ... In another word, How I can exchange ?
Code:
argc == 3
and
Code:
argc == 2
To enter file name ? i mean what i should do to in
Code:
rabin.split(argv[1])
To pass my file name by use keyboard not Project properties/Debugging?)
the below code is just the main function of program, and the whole of it in this link [URL] .... Information Dispersal Algorithms Rabin-IDA.
Code:
#include "include.h"
void __cdecl _tmain(int argc, TCHAR *argv[]) {
DWORD ini=GetTickCount();
try {
if( argc == 3 ) //recombine
[Code] ....
I know I should use getline() function but how exchange argv[] ?
View 1 Replies
View Related
Jan 21, 2015
#include <iostream>
int ival1
int ival2=1
int summe
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
[Code] .....
If I compile it I've got these errors
[Error] expected initializer before 'int'
recipe for target 'rechnen.o' failed
View 14 Replies
View Related
Jan 21, 2014
This first Dowhile loop is saying "expected unqualified-id" at the do and while parts. What does that mean
do {
do {
do {
std::cout << "Give me a test result or grade from 0 to 100 for class"<< 1 << std::endl;
std::cin >> mathaverage[mathtestcount];
loopresult=1;
[Code] .....
View 2 Replies
View Related
Dec 2, 2014
I can't figure out this error.
#include <iostream>
using namespace std;
bool isPrime(int number); {
primeNumber = isPrime(number);
[Code] ....
View 2 Replies
View Related
Apr 23, 2013
I have a global var (m) with an initial value 5.
I have a template class (A) that derives from a either a base class that has a member (_A1.m) or not (_A0), based upon it's template parameter. class (A) has a member function (fn) returns the value of (m) as it understands what (m) is.
However, this gives different results compared with a non-template class in a similar scenario. I'm expecting that if derived from _A1, that m should be taken from the base class scope and if derived from _A0, it should be taken from the global one.
Here is the code for your amusement:
int m = 5;
class _A0 {
public:
_A0(int) {
[Code] ....
This compiled using g++ 4.5.3 and 4.6.3 with the same results:
Global value of m is: 5
B0 class has no internal m member. Object resolves m internally with value 5
B1 class has internal m member. Object resolves m internally with value 3
A<_A0> class has no internal m member. Object resolves m internally with value 5
A<_A1> class has internal m member. Object resolves m internally with value 5
View 2 Replies
View Related
May 20, 2013
In this code:
#pragma once
#include <iostream>
class CBox // Derived class {
public:
// Constructor
explicit CBox(double lv = 1.0, double wv = 1.0, double hv = 1.0) : m_Length(lv), m_Width(wv), m_Height(hv){}
[Code] .....
Before the program ends, at return 0;
I would expect the CBox destructor to be called 3 times but it is being called 6 times? Why? Also in this code:
#pragma once
#include <iostream>
class CBox // Derived class {
public:
// Constructor
explicit CBox(double lv = 1.0, double wv = 1.0, double hv = 1.0) : m_Length(lv), m_Width(wv), m_Height(hv){}
[Code] .....
Why is the destructor called 3 times? When have you really destroyed a CBox? Doesnt emplace only create it and store it, then thats it?
[URL] .....
For pushback:
void push_back(value_type&& _Val)
{// insert by moving into element at end
if (_Inside(_STD addressof(_Val)))
{// push back an element
size_type _Idx = _STD addressof(_Val) - this->_Myfirst;
[Code] .....
View 12 Replies
View Related
Sep 14, 2014
I just wrote the following simple program:
Code:
#include <stdio.h>
#include <math.h>
int main(void) {
float fx, x;
[Code] ....
The output increases x by 0.1 as expected until x=1.5. After that x becomes 1.600001 and not 1.6 as expected.
View 9 Replies
View Related
Aug 22, 2014
I'm trying to perform a simple input operation, and check to make sure that whatever the user input is a valid input (is within data type bounds, is correct data type...). But when I get to ignoring the input, I keep getting an error.
unsigned short num;
while (true) {
std::cin >> num;
if (std::cin.fail()) {
num = 1;
[Code] ....
I don't fully understand why this error is here.
View 6 Replies
View Related
Nov 15, 2014
I'm working on a school project learning C++. I'm running into an error I can't seem to find the answer for (see topic title).
main.cpp
#include <iostream>
#include <string>
#include "Signature.h"
#include "Genome.h"
using namespace std;
// Calling Function
int main() {
Signature Sig1; // Create Signature object
Genome gString1; // Create Genome object
[code]....
View 1 Replies
View Related
Apr 3, 2014
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
using namespace std;
class CV {
public:
char name;
char qualfctn;
[Code]....
View 1 Replies
View Related
Mar 1, 2015
#include <stdio.h>
#include <math.h>
main() {
int n;
int k;
int j;
//gets user input for length of string
printf("Enter the value of n:");
scanf("%d", &n);
[code]......
When I compile my code I get an error saying that I need declaration specifiers in my is_prime subroutine in the for loop.
Here is the line of code it references.
for(j = 2; j < k; j++)
View 2 Replies
View Related
May 2, 2013
I am trying to parallelize some of my code with OpenMP. When I switch to using multiple threads I start getting random numbers that are out of the expected range.
Here is a small example:
Code:
#include <stdio.h>
#include </usr/local/include/gsl/gsl_rng.h>
#include </usr/local/include/gsl/gsl_randist.h>
int main() {
int mySeed=0;
const gsl_rng_type *T;
T = gsl_rng_ranlxs2;
gsl_rng *r_1 ;
[Code] .....
gsl_rng_uniform should only output number in the range [0,1) but with multiple threads it outputs larger number as well.
View 2 Replies
View Related