C :: Working With Files / Struct And Manipulating Data
Dec 17, 2013
I have the following code and I am trying to do simple math calculations to the data. I need to take the car price (y) minus down payment (z) and then divide that quantity by 12 times "yearsx" That answer is then assigned to x. The problem is that x will not print the correctly!I also noticed that if I increase the "count" to amnything higher than the number on lines in the file, I get the correct value for x but only on the last set of the struct..my file reads as follows:
last_name first_name car_price down_payment years
johnson bill 10,000 2,000 3
When I printf the struct to the screen, i need to do the following:
x = (10,000 - 2,000)/(12*years);
but this is the math part that wont work. I have checked and doubled checked number types and I cant get it right.
Code:
#include<stdio.h>
#include<stdlib.h>
#define FILENAME "file.txt"
#define SIZE 100
}
[code]....
View 3 Replies
ADVERTISEMENT
Jul 11, 2012
I am writing a little OS agnostic library for my team for manipulating files.
One such function is used to move/rename files (only files, not dirs). I got into a little argument with a colleague about naming: "rename" or "move"?
"move" makes more sense, but the c api calls it rename.
Is there any historic (or actual) difference between a "rename" and a "move" we could base ourselves on? Or is this purely an Apples vs Oranges?
View 6 Replies
View Related
Jan 31, 2015
So, it seems I have a bug in my code:
Code:
char *mem = malloc(9), *bottom = malloc(3), *in = "abc";
int position = 2, i;
mem = "onetwo";
printf("OLD mem = %s
", mem);
[Code]....
What I'm trying to do is insert "abc" in the 3rd position of "onetwo". Results would be "oneabctwo", but all I get is crashing.
View 9 Replies
View Related
Sep 28, 2014
How can I manipulate a data in a file for example the saved file is like this:
code name Price Quantity
001 hammer 100 4
002 screwdriver 100 4
what i like to do is:
1. the user will be ask to enter its code
2. will output the searched code and then
3. the user will be ask to enter how many pcs he/she will buy.the formula should be
pcs=pcs-users_input if the user selected the code 001 and enters only 1pc it should be updated to only 3 pcs left in the file.
View 5 Replies
View Related
Apr 10, 2014
We were given a task to use lists and iterators. We were supposed to make them from scratch. I'm done with that. The problems that I'm having are as following:
1. I'm not able to access the list made of Course datatype which is present in each Student instance. Does this mean I need to make an iterator for that course list inside the student class?
2. Similarly since I don't have direct access to The course list so I added the course into the Student list through the student objects not through the iterator. How can I do it through the iterator?
3. Printing of a particular student and his courses is not happening as my iterator made for student only prints out the students, not the courses present in their courselist. How to do that?
Here's the code
#include <iostream>
#include <string>
using namespace std;
const int ILLEGAL_SIZE = 1;
const int OUT_OF_MEMORY = 2;
const int NO_SPACE = 3;
const int ILLEGAL_INDEX = 4;
[Code] .....
View 1 Replies
View Related
Jul 7, 2012
File Data format
A,A
A,B
C,E
C,F
And so on ... it could be up to any alphabet. The number of As and Bs and Cs and Ds in first column depends on the number of unique alphabets used in the first column. For example the unique alphabets used in this case are 2 (A,C) hence each alphabet appears in the first column of consecutive 2 rows.
Which means
Code:
A:A,B,C,D
B:B,C,D,E
C:C,D,E,F
D:D, ,F,G (E is missing)
Actual Data
A,1
A,2
A,3
A,4
C,18
C,33
Final Solution: Add each integer value to its previous value and store the resulting value.
View 8 Replies
View Related
May 14, 2013
Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct BOOK
{
int* price;
} Book;
[Code] ....
View 1 Replies
View Related
Jul 26, 2013
I have created a project in netbeans 7.2 and have not modified any setting. I have used all sorts of methods I could think/find but the code can not find the file.
I have placed my test.txt file in the folder of the project. Here is the location of the file:
C:UsersSAMARASDocumentsNetBeansProjects
eadFi le
However, I could not use it without modifying it as an absolute path.
For example, check the code from the FAQ. //well the return 0; is missing but this is not the problem now.
Or for example this code Code: bad code or with Code: myReadFile.open("C:/Users/SAMARAS/Documents/NetBeansProjects eadFile est.txt"); I have tried many things for placing the slashes, but could not find the file.
View 6 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
Dec 27, 2012
I'm trying to calculate a series of times from start to end, and find out the duration between them, sum them up and see if they're above a certain value or not, for each particular instance.
My goal is to provide a prepared text file with time tags such as this:
Mon 19-Nov-2012 09:12 Mon 19-Nov-2012 09:34
Wed 21-Nov-2012 13:14Wed 21-Nov-2012 17:11
Fri 07-Dec-2012 15:21Fri 07-Dec-2012 15:26
=============================================
Mon 26-Nov-2012 12:50Tue 27-Nov-2012 15:29
Wed 12-Dec-2012 13:07Wed 12-Dec-2012 14:58
Fri 14-Dec-2012 14:22Fri 14-Dec-2012 14:29
And the program is able to calculate the total time relevant to each instance (instances separated by a line of '=').
Some form of number should somehow identify each instance or something similar and a text file is generated with total time printed for each instance. E.g.
Instance 1: 00h22m + 03h57m + 00h05m = 04h24m
Instance 2: 04h15m + 07h44m + 01h51m + 00h07m = 14h04m
Now I'm currently working on making the logic to calculate time within the ranges I'd like based on several parameters.
Are there any references I can use when it comes to working with strings in order to seek and extract these values in order to work with them? The documentation available on this website, despite being very informative, does not show practical applications of said class and I'm at a loss on how to implement the functionality.
View 17 Replies
View Related
Jul 10, 2013
I have written the following code to add data to text files which are required to store 3D scan data (I have to calculate the y-coordinate). My code seems to work except that it stops working when I want to create more than ten text files i.e. the directory I am trying to store them in will not hold any more than ten text files. Code is shown below.
#include <string>
#include <locale>
#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
[Code] ....
View 1 Replies
View Related
Feb 27, 2014
i need my code to stop outputting all the numbers throughout the steps it is going through i just need it to output the total
this is my input
M
C
C
C
L
I
V
and its output is
Your total is 1000
Your total is 1100
Your total is 1200
Your total is 1300
your total is 1350
Your total is 1351
i just need it to output the last number
// write a program to read a string of characters
// that represent a Roman numberal and then convert
// to Arabic form ( an integer
// input from data file
[Code].....
View 1 Replies
View Related
Mar 13, 2013
This code will show the data from the .txt file "file1" the data is (0.0 0.1 0.2 0.5 0.8 0.9 1.0)
What I'm trying to do is take these float values and add them all up and divide them by 7 (finding the average and output that)
Convert it into a percent and print it in a field:
Width of 6 with 2 digits after the decimal point...
I tried doing something like cout << "the average is: " << data/7 << endl; but that didn't work. I got an error that said "/" was not an operator.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream myfile("file1.txt");
string data;
getline (myfile, data);
cout << data << endl;
myfile.close();
return 0;
}
View 1 Replies
View Related
Sep 13, 2013
I am trying to enter data to a structure some 8 times, but not able to do so. Here is my code.
Code: #include<stdio.h>
struct _Timer {
unsigned int HH;
unsigned int MM;
}Time[8];
[code]...
But when I enter any data and press enter , the .exe file stops working and not able to enter data.
View 4 Replies
View Related
May 2, 2013
So this is the last part of a program I've been working on for four weeks now. This question may be a tough one considering the amount of files included in the program.
The program is to read in a file of requests between two cities, read in a file of flights and cities that occur between the cities. It then checks to see if there is a path between the flights and output an itinerary. I have the correct itinerary outputting, but when attempting to output the associated flight number and price according to the city, I am getting odd data. How can I output the correct flight number and price associated with each flight on the itinerary.
I'll post out the output I am currently getting and the section where I am outputting the data. I'm sure I'll need to post more files so the program can be understood.
Don't want the code done for me, just a point in the right direction! I don't want to let this program defeat me!
Output: Code: Request is to fly from Atlanta to San-Diego.The flight itinerary is:
Flight # From To Cost
10 Atlanta Chicago $134529069
10 Chicago Miami $134529069
10 Miami Dallas $134529069
10 Dallas San-Francisco $134529069
10 San-Francisco San-Diego $134529069
This function finds a path between cities. Code: bool flightMap::IsPath(string originCity, string destinationCity){
StackClass aStack, bStack;
flightStruct flightRec;
string topCity, nextCity;
bool success;
int index = 0;
[Code].....
View 1 Replies
View Related
Mar 28, 2013
I was looking at some linked list material and was wondering something. Can you initialize a data member inside a struct like in C++? i.e.
Code:
typedef struct node
{
int data;
struct node * next = NULL; // this is the line in question
} LLnode;
View 3 Replies
View Related
Mar 24, 2013
I have a queue of structs. I would like to access one of the two pieces of data at the front of the queue that each struct maintains.
Here is some of my code:
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <queue>
using namespace std;
[Code] ....
What I am asking is how do I get the priority of the struct item at the front (lane1.front()), in this case?
View 8 Replies
View Related
Nov 21, 2013
I am working on this project where I need to see if data in a struct has changed and if so I need to do something. With that being said, is there a way to check to see if data in a struct has changed. My first approach was to make a copy of the struct and compare the original struct with the copy but I was having problems with the operator==.
View 2 Replies
View Related
Oct 24, 2013
I was working with binary search tree and came up with the solution:
Code:
#include<stdio.h>
#include<stdlib.h>
typedef struct data {
int x;
struct data *left;
struct data *right;
[Code] .....
View 6 Replies
View Related
Feb 23, 2015
I have a struct like this:
Code:
struct String{
char* data;
std::size_t size;
};
I would like to be able to create const variables of this type for string literals.
Code:
const String message;
Is there an elegant way to create a const String like this when data is a string literal?
I tried this:
Code:
const char *string_data = "Hello";
size_t string_size = strlen(string_data) + 1;
const String string = {string_data, string_size};
The problem with that is that string.data isn't considered const during the initialization of the String struct so the compiler throws an error. It doesn't feel very elegant to do it like this either way.
Is there an elegant solution to this problem? I would like to avoid making a copy of the string literal.
View 7 Replies
View Related
Aug 14, 2014
How can I read this file in to my struct?
12345Joe Lim KH879.00
12233Kay Suet Yee35.98
23781Leong Jing Yang 10.00
67543Woon Tian Yi500.50
struct master {
unsigned short int IDnum;
[code]....
not working
View 16 Replies
View Related
Feb 8, 2013
at my work we use a static analysis tool and it is pointing out some uninitialized variables. One of which is a class member variable which is a C struct. Now, that variable is already declared in the header file for the class.
Currently in the class constructor I am doing:
Code:
memset( &thestruct, 0, sizeof( thestruct ) );
Is there a C++ way to do this? I Googled this but all I really found was:
Code:
StructDef thestruct = {};
Which doesn't really apply here.
View 7 Replies
View Related
Feb 6, 2015
I found this elegant looking code on the net that claims to be able to manipulate an images colors using ColorMatrix.
When I run it, it does nothing! I used the code exactly as is with no editing, except to feed it my own image to do its work.
private void ApplySaturation(float saturation) {
float rWeight = 0.3086f;
float gWeight = 0.6094f;
float bWeight = 0.0820f;
float a = (1.0f - saturation) * rWeight + saturation;
[code].....
View 8 Replies
View Related
Sep 23, 2014
Implementing and manipulating a Polynomial ADT using a linked list.
So far I have:
poly_ADT.h
Code: typedef struct nodeT{
int coef;
int powr;
struct nodeT *next;
} node;
[Code]...
I need to create a function that creates the polynomial using input first.
poly *poly_create (num,...) ;return a new polynomial with num terms terms are listed in order of lowest ordered-term to highest. i.e., to initialize poly 15x^6 + -9x^4 + 3x^2 call poly_create(3, 3,2, -9,4, 15,6 );
Once I do that I need to implement various functions that can manipulate the polynomial itself but I'm having trouble just with creating the polynomial itself, how to do that using a linked list and nodes?
View 3 Replies
View Related
Mar 5, 2013
I need manipulating a set of containers. I created a vector that contained vectors of objects:
std::vector< std::vector<Terrain> > mapArray(num1, std::vector<Terrain>(num2));
where num1 and num2 are arbitrary numbers. and Terrain is the class of objects I'm trying to store.
I want to be able to use push_back on both the main vector and the vectors within the mapArray vector but I'm unsure of how to target the inner vectors with push_back. How to dynamically store a 2D array of objects.
View 10 Replies
View Related
Aug 30, 2013
The problem is I have a function which sets some variables and I want to access the variables, but myfunc() is nested too deeply for me to pass a data structure all the way down and to return all the way up. The functions reside in different files. I'm not allowed to use extern structs (i.e. a global variable).
How to use a class and instantiate it in myfunc(). My solutions are:
- using the singleton class method
- static variables and function residing in the class (but I'm suspicious of this way. seems like it's just class variables masquerading as global variables.
View 2 Replies
View Related