I am having a lot of trouble being able to get data from a file and input it into given structs and arrays of structs and then outputting the file. We are given a file that contains 96 lines and looks like this:
Arzin, Neil 2.3 6.0 5.0 6.7 7.8 5.6 8.9 7.6 Babbage, Charles 2.3 5.6 6.5 7.6 8.7 7.8 5.4 4.5
This file continues for 24 different people and then repeats with different scores (the second line). The first number, in this case is 2.3 for both people is a difficulty rating. The next 6 numbers are scores.
We are given this data in order to set up our structs and arrays and my code:
#include <iostream> #include <fstream> #include <iomanip> #include <string> #include <cmath> using namespace std; int main () { ifstream inFile; inFile.open("C://diveData.txt);
Following is the program I wrote it basically takes 9 inputs and then save them into binary file. then print out the data stored in binary data and find inverse of it then print the inverse out. but its stuck in a loop somewhere.
Code: #include <stdio.h> int main() { int a[3][3],i,j; float determinant=0; int x; FILE *fp = fopen ("file.bin", "wb");
Where course code is the 4 numbers after the name together and the term is the letter and year in the last two pieces of info. I got this to work:
int main() { FILE *p; p = fopen("input.csv", "r+"); if(p == NULL) { puts("The file could not be opened");
[Code] ......
But lets say i dont know how many lines i have in my file and i want to count them and then use that size for my array so i tried this by:
int main() { FILE *p; int lines = 1; char ch; p = fopen("input.csv", "r+"); if(p == NULL) {
[Code] .....
But the second program is not working for unknown reasons. I do not get any errors but its not scanning the info because when i print the info later on it prints out random symbols.
And I want to make adding,deleting, and searching functions.Something like
Code:
void add();//Add name and address to a file, //and add more to the same file if I want to. void del();//Delete or Change some neighbor's name or address //in the same file(Can I?) void search();//Search name and show detail
So I started to code adding function first, but I don't know that I need to use pointer to code each functions relations, and I don't know how to check that my input's already exists yet. But I started some code below...
Code: void add() { int i=0; FILE *fp = fopen("neighborhood.txt", "at"); if ( fp != NULL ) { do{
I'm trying to read the data from a file i/o and put them into an array of structs. But when I run the program, it gives me a bunch of "garbage" as an output. my code and see
I need to create a program which could create text files of the bits stored in avi file/binary file. My first requirement is to show 0s and 1s in the text representation . My second requirement is to create an avi file from this text file. I have tried few codings but either they give me error or they not playing the reconverted binary files.
I am trying to get the code to read from the txt file one bite at a time and then write this bite into the binary file but i cant seem to get it working.
FILE *fpcust, *fpcustbin; //<<<<<-----point to both sales and customers text files, and the new .bin files for both char buffer; int ch; int ch1; fpcust = fopen("c:customers.txt", "r"); //<<<<-----pointing to the file fpcustbin = fopen("c:customers.bin", "wb"); //<<<<<-----pointing to the new binary file, opening in writing binary
I just wrote a program for Huffman Encoding, where I take a text file, encode it in the form of 0's and 1's, and save that as another text file. However, this does not solve my purpose as it is taking even more space.
So I want to know how do I convert a text file containing these 0'S & 1's to a binary format.
I'm working on a project involving nested classes and structs like this:
Code: class A { public:class B { public:f() {A::C* iCanDoThis; //no errors. iCanAlsoDoThis->root->.... //this also works fine.}private:A::C* iCannotDoThis //this is what I would like to do. Has errors A* iCanAlsoDoThis;};private:struct C {..data..};
C* root;};
Is it possible make a pointer to struct C a private member of class B?
The main is not working properly, I get strange missing parenthesis notices and array errors which I am not understanding. How to identify the errors. Functions are included.
Code: #include <stdio.h> #include <stdlib.h> #include <string.h> int menu (); double change_value (double * value);
I'm currently working on a program that writes an array of struct to a file and then read back the data from the file to another array of struct. At the bottom is an image of my result.
My goal is to end up with two identical struct arrays but my program fails to do this. My struct have to members: ID and kind (of animals in this case). I declare my first arraystruct africa[] with "monkey" and "giraffe" with their respectively IDnr: 112 and 555. I stream this data to a file and read read them back to the arraystruct get_animal[]. Simply I want the get_animal[] to be identical with the africa[] when the program is over, but that is not so. According to my result(bottom image) it display:
112, monkey (get_animal[0]) 112, monkey (get_animal[1]) meaning that get_animal[0] is identical to africa[0] get_animal[1] is also identical to africa[0]
but why? I want get_animal[1] to be identical with africa[1]. meaning I want the result to look like this:
112, monkey 555, giraffe
I've also made the program to print the parameters of my fwrite/fread calls. Why is the 3rd parameter = 1 meaning that only 1 element will be read/written when my program just read/write 2 elements?
How would I be able to have this display the rest of the households without having to have 13 separate cout lines(one for each household)? In other words, how can I set it up to increment the output?
#include <iostream> #include <iomanip> #include <string> using namespace std;
I think i am getting confused with passing structs and functions all in the same...When I run through the program (it compiles), the functions that add coins do not add, but rather just replace an old value with a new one.
#include <cstdlib> #include <iostream> using namespace std; struct coinbox {
I can't seem to remember everything I should about constructors. I'm looking for a way to create an array of structs, using a constructor. My code should explain.
struct myStruct { private: int structInt1, structInt2;
I get an error telling me that foo is undefined, and that declaration of function_example(int x, int y) is incompatible with the declaration of it in the header file.
I have an assignment where I need to use pointers to do a few things and I am a little confused on the syntax of it all. My question is how do you use a pointer to point to an array of structs.
For example
struct info{ char firstName[15]; char lastName[15]; }; main() { info person[4]; cout << "The third letter of the second persons first name is: "; // ????? }
how would I define a pointer to point to the third letter of first name the second person in the "person" array.
How to fill a vector with structs that are read in from a separate file. Each line in the file would read for example "Doe John M 26" for the name of the person, gender and age. I just need to get pointed in the right direction so I can get this started.
Write a program for the following problem. You're given a file that contains a collection if IDs and scores (type int) for an exam in your computer course. You're to compute the average of these scores and assign grades to each student according to the following rule:
If a student's score is within 10 points (above or below) of the average, assign a grade of satisfactory. If a studnt's score is more than 10 points above average, assign a grade of outstanding. If a student's score is more than 10 points below average, assign a grade of unsatisfactory.
The output from your program should consist of a labeled three-column list that shows each ID, score, and corresponding grade. Use a struct to store each student's data and an array of structs to store the whole class. The struct should have a data member for id, score, and grade.
what I am trying to do is to pass to a function the address of an array of structs, so I can later modify the items within the struct, within the array
Code: typedef struct { //A struct of name auctionint bidder;float bid;} auction; void myFunction (auction * auctionItem[]){(*aucItem[x]).bid = y;(*aucItem[x]).bidder = z;} int main(){auction theItems[10]; myFunction(theItems);} Where x, y, and z can be any number.
When I try to run my code the IDE (I'm using Code::Blocks 12.11) does not give me any errors, but it does give me a warning:
warning: passing argument 3 of '<function name>' from incompatible pointer type [enabled by default]
and the note:
note: expected 'struct <struct name> **' but argument is of type 'struct <struct name> *'.Also, when I run the program, it will crash and return garbage.