C/C++ :: Apply Arrays In Files?
May 13, 2014
I am Trying to make my program read 10 integers from a user-named file using arrays, but I encountered logic error because the calculations turns out to be wrong. my question is, Am I supposed to use arrays with files? if so, What is wrong? it runs fine but only the calculation is WAY OFF!
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int SIZE = 10;
void input(const int a[], int size);
int getTotal(const int a[], int size);
[Code] ....
View 14 Replies
ADVERTISEMENT
Mar 10, 2014
I am trying to learn about parallel arrays and files. I believe that I wrote a program that properly writes the data of the arrays into a file, but I am not quite sure how to take the next step and make a second program by bringing in the file I created and reading the information of the file back into two arrays to display them.
Code:
#include<iostream>
#include<fstream>
#include<string>
usingnamespace std;
[Code] ....
View 5 Replies
View Related
Jan 12, 2015
how to write a password cracking program that will try all possible char combinations for just two chars (without duplicating any combination guesses). Obviously, there would only be 4 possible truth table combinations for two boolean values, but how would a person calculate the number of all possible combinations for two values with 70 different possible chars?
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
static const char alphanum[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
/*
Boolean Truth Table for two values:
p q
-----
T T
T F
F T
F F
Note that there are 70 chars in all specified above.
It will require much more than a simple truth table to try every possible char combination (especially if the password to be cracked is 2 or more chars). Using this guy's code: [URL] ..... as a starting point, I'm writing a program that will crack a password with a length of just 2 chars.
*/
int stringLength = 2;
char genRandom() {
return alphanum[rand() % stringLength];
}
int main() {
std::string password = "Sp";
srand(time(0));
std::string Str;
[code]....
View 19 Replies
View Related
Jul 11, 2014
I was trying to put mutex lock on shared memory but my code is not working. What I want is that if some process is putting something on shared memory segment, other process should not be able to access that segment. For testing , I create a server program which put data in shared memory and client program which access the data.
To test it, I put break point after:
pthread_mutex_lock(&(init_lock));
But I see that client program was able to access shared memory.
Below is code:
Server: Code: pthread_mutex_t init_lock = PTHREAD_MUTEX_INITIALIZER;
main()
{
char c;
[Code].....
View 1 Replies
View Related
Sep 8, 2013
I am trying to do a simple calculation. I just started C++ and learning about decisions. My program should calculate number of tickets and apply discount based on the number of tickets purchased. It will only execute one of the decisions.
#include <iostream>
using namespace std;
int main() {
double qty; // qty of tickets
double discount; // % of discount.
[Code] ....
View 7 Replies
View Related
Dec 7, 2014
I need to apply theme file in windows form but I can't. When I use the code below I get error because there is no System.Windows.Application
StreamResourceInfo sri = System.Windows.Application.GetResourceStream(
new Uri("App.xaml", UriKind.Relative));
var resources = (System.Windows.ResourceDictionary)Load(sri.Stream); ;
var app = new System.Windows.Application();
app.Resources.MergedDictionaries.Add(resources);
View 2 Replies
View Related
Feb 21, 2012
I am trying to apply gabor filter to a fingerprint for fingerprint enhancement using c.
My image size is 280x340.Gabor filter equation is :
F(x,y) = exp(-0.5*[x^2/sigma_x^2 + y^2/sigma_y^2]) * cos(2*PI*f*x);
I am able to execute this equation.But my problem is i am calculating the equation for 280x340 times and it is taking time(4 sec 2.93GHz 3GB ram).
how to reduce the executation time ?
What I know exp function is taking time. So is there any equivalent of exp which will take less time to execute ?
View 6 Replies
View Related
Dec 15, 2014
My problem is when I try to show the contents of my text files after I add a contact it wont show me anything.
#include <iostream>
#include <conio.h>
#include <string>
#include <windows.h>
#include <fstream>
#include <cstdlib>
using namespace std;
//prototypes
void printline(char, int);
[code].....
View 3 Replies
View Related
Aug 21, 2012
How to open a image in paint mode after that how to apply graphics to that opened image in paint mode.I am attached a image i want to draw a center line in that image..
Attached Images point1.jpg (12.9 KB)
View 1 Replies
View Related
Apr 5, 2013
I am writing a program to hide files behind other files using Alternate Data Streams in Windows NTFS file systems.
The program is as follows:
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void){
char hostfile[75], hiddenfile[75], hiddenFileName[15] ;
printf("Enter the name(with extension) and path of the file whose behind you want to hide another file: ");
scanf("%75s", hostfile);
[Code]...
The complier is showing error as "Extra Perimeter in call to system" but I am not getting where?
View 4 Replies
View Related
Jan 16, 2014
I am writing a piece of code that requires me to display the last 1000 lines from a multiple text files (log files). FYI, I am running on Linux and using g++.
I have a log file from which - if it contains more than 1000 lines, I need to display the last 1000 lines. However, the log file could get rotated. So, in case where the current log file contains less than 1000 lines, I have to go to older log file and display the remaining. For e.g., if log got rotated and new log file contains 20 lines, I have to display the 980 lines from old log file + 20 from current log files.
What is the best way to do this? Even an outline algorithm will work.
View 6 Replies
View Related
Feb 6, 2014
I define "Comwords" as a string, but apparently it takes the members as chars, then I can't set strings in a structure equal to the chars.
I see to also be having unknown problems with the ComMAL array and loading it values into another element of the same structure.
How to correct this? I was thinking of casting char elements as strings, but could find no reference in my library book regarding how to do that (lots on casting int's a doubles...)
Code:
int _tmain(int argc, _TCHAR* argv[]) {
int comm = 10;
int targ = 5;
int death;
struct AI_WORDS
[Code]....
View 2 Replies
View Related
Jul 1, 2014
Using a for loop, construct two 100 element arrays, x and y, such that element i of x stores the value sin(2*pi*i/100)) and the corresponding element of y stores cos((2*pi*i/100)). Print the values stored in the elements of x and y as you calculate them.
I have attempted to solve it but I'm not sure why the value 0 is only being printed, maybe I haven't assigned sin(2i/100)) and cos((2i/100)) to the arrays properly?
Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main () {
[Code] .....
View 3 Replies
View Related
Sep 16, 2013
When including a header file in stdafx.h, should that file still be included in the source file where it is actually used?
If it is included in both places, is the one in the source file ignored?
View 5 Replies
View Related
Dec 17, 2014
int arr[4][5];
for (int(&row)[5] : arr){
for (int &column : row){
} }
Why do we name it row instead column?
int arr[row][column]
Wouldn't this be like
int arr[4][5];
for (int(&column)[5] : arr){
for (int &row: column){
}
It just seems funny to me because we use row[5] which should be 4 if we meant row? Or did I read it wrong in C++ prime !?
View 2 Replies
View Related
Apr 15, 2013
I'm trying to write a function that takes a 32bit address and a data to store at this address.
I'm wanting to take the 32 bit memory address eg 0x12345678 and split it
into 4 x 2 bytes
12, 34, 56, 78
then each of the 4 entries is at most a 256 entry array.eg
FF, FF, FF, FF
So in this example, 0x12 points to 0x34 in the second array, which points to 0x56 in the third array, which finally points to 0x78 in the last array. This last array holds the actual data.
After successfully doing 0x12345678, say I might get a read for 0x1234AABB. So, the first and second pointers already exist, but I then have to create and write to dynamically created arrays.
The arrays need to have all entries set to NULL so that i know whether to follow the pointers to overwrite a previously entered value or create new arrays and pointers.
It all looks good and simple in the pseudo code I've written up but I'm having trouble coding it. I'm currently trying to deal with the first entry case, ie all array elements are NULL, but I'm getting confused with the pointers and creation of new arrays.
void cpu::store(unsigned int mem_add,unsigned int mem_val) {
int first = (mem_address&4278190080)>>24;
int second = (mem_address&16711680)>>16;
int third = (mem_address&65280)>>8;
int fourth= (mem_address&255);
[Code] .....
A1 has been declared as
int* A1[256] ;
View 3 Replies
View Related
Feb 26, 2013
How do I read a .pdf file using C++? When I try to open it using myfile.open ("example.pdf"); but all I see is some Crazy Symbols. Is there any way to open ?
View 3 Replies
View Related
Feb 2, 2015
I need a program that can compare two xml files for equivalency using any XML Parser.
View 2 Replies
View Related
Apr 28, 2013
Assignment: Write a program that merges the numbers in two files and writes all the numbers into a third file. your program takes input from two different files and writes it output to a third file. Each input file contains a list of numbers of type int in sorted order from the smallest to largest. after the program is run, the output file will contain all the numbers in the two input files in one longer list in sorted order from smallest to largest. your program should define a function that is called with the two input - file streams and the out - put file stream as three arguments.
Okay, here is my code.
#include<iostream>
#include<fstream>
using namespace std;
int main() {
int list1[25];//array for the first list
int list2[25];//array for the second list
[Code] .....
I'm confused about where the two files (which contain lists of numbers) need to be placed in order to be read and if they need to be renamed or something.
View 1 Replies
View Related
Oct 24, 2013
I want to know if you can run bat files from code? If so how else how can you shutdown a computer with code? OS is windows 7.
View 2 Replies
View Related
Mar 19, 2014
So I am awful when having to use data or .txt files. I believe my code is right, I just don't know how to upload the files. Here is the description of the assignment and the coding:
Process the input file containing latitude and longitude data of US cities in degree, minutes, and seconds. Output the processed information in decimal degrees.
a) Write a C++ program to read each line of the input file, store each data line in an array of structure, calculate the degrees in decimal for latitude and longitude, store these values in the corresponding structure and write the results to the output file by processing the array.
b) Use vectors or dynamic array to optimize memory usage. Specify the design choice in your main comment for the program.
c) Split the City and State and store it in two separate fields.
d) Search a city and find it in the array of structure and print out ALL the information on the screen.
#include <fstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
struct City
[Code]...
View 3 Replies
View Related
Dec 6, 2014
I'm using maps and writing files for the first time and I get a crazy compiler error when I try to compile the following code.
//map is named schedules
// saveSchedule() is a member of the Schedule class that writes a vector of objects to disk, or is supposed to
ofstream newFile("sched.txt");
map<string,Schedule>::iterator in;
[Code] .....
View 3 Replies
View Related
May 18, 2014
I have a program below that calculates the average, sum, etc of the numbers in a file named "mynumberlist1.txt".
I want to create a loop whereby the program loops through several files; mynumberlist2.txt, mynumberlist3.txt, and calculates the statistics for all relevant files using the calculations below. How would I do this?
#include <iostream>
#include <cmath>
#include <math.h>
[Code].....
View 1 Replies
View Related
Sep 26, 2014
I don't have in depth code or anything. I tried this but can't seem to wrap my head around it.
Code: //header.h
namespace test {
int arr[5];
[Code] ....
Also tried putting int arr[5] in a Test class within test.h.
I have 2 structs in another file, the main, and want to make an instance of the arr variable, in a separate header, for each.
View 2 Replies
View Related
Mar 31, 2014
I have a text file that contains values as follows:
2013 05 27 15 52 02.049824 231.401 0.022 49.738 2013 05 27 15 52 02.668822 229.814 0.019 49.738 2013 05 27 15 52 03.283705 228.528 2.599 49.726 2013 05 27 15 52 03.898469 230.140 2.576 49.751
Column1=date, Column2=Month, Column3=Day, Column4=Hour, Column5=Minute, Column6=Seconds, Column7=Voltage(Vrms), Column8=Current(Irms), Column9=Frequency(Hz).
I have to develop a program that will analyse these time-sampled voltage and current measurements over 24 hours and find the total energy used, mean and peak power consumption and Energy used over each hour of the 24 hour period.
How do I go about doing this? I also need to include at least one numerical integration technique. The file data contains over 50 thousand lines in the format mentioned above.
View 2 Replies
View Related
Jun 11, 2014
I would like to make a program that automatically launches and loads a file when a file of that file type is double clicked within windows. As said I am unsure where to look for some information as to how to do that, and so turn to you all. Is there a simple way of doing such a thing without using any external libraries, if so, a simple tutorial or link to a reference for this; if there is no way of doing this without externals what would be a small and simple to use library for this?
View 2 Replies
View Related