I have run across what I believe to be a syntax problem which I don't understand. I have a structure with two character array and I need to be able to change the size of those array dynamically. I have to use character arrays and I think the dot notation. I am not sure if I can use arrow notation. I can not do this problem using strings and vectors.
#include <iostream> #include <cstring> using namespace std;
I was wonder if I can make 2 different size structures in a file. I wrote a code but It's apart of my school project and I havent compiled it yet, so Im just wondering will this work?
Code: if((stsPtr = fopen("status.dat", "rb")) == NULL){ prinft("File could not be created/opened. "); Error();
I have to write a program that reads from a text file, which contains a list of stock hourly prices and the company names. Something like this:
78.52 82.56 75.10 71.97 Water Company 22.40 25.68 21.37 22.96 Mega Shipping Inc
There's suppose to one array of companies, where each company will be kept in a structure that contains: a pointer for the name, an array of the prices, and the average price for the day. The structures will be kept in an array of structures.
My question is, how do I read the data from the file and put the data from each line into the next structure in the array of structures? I read the numbers in fine. I just use:
Osgood,Marcus 298542123 CHM FR mosgood@whatever.edu Cronk,Melissa 873489021 BIO SR mcronk@whatever.edu Pry,Seth 349908431 MTH SO spry@whatever.edu Langlais,Susan 783323545 ME SR slanglais@whatever.edu Davis,Nicole 987543345 PHY FR ndavis@whatever.edu
It's supposed to split it up into name, ID number, major, year, and email. The file reads it without any errors, and assigns name to the first part of the structure. However, ID gets assigned the ID, major, year, and email. Then Major gets assigned major, year, and email. Year gets assigned year and email, while email just gets assigned email. I don't know if it has something to do with the loop. For example, this is what I get what I print just the name and the ID.
Cronk,Melissa 873489021BIOSRmcronk@whatever.edu
Pry,Seth 349908431MTHSOspry@whatever.edu
Langlais,Susan 783323545ME
Davis,Nicole 987543345 PHYFRndavis@whatever.edu
Anyway. This is my function code for reading the array. I have it printing the ID number just to see if I can catch the errors earlier:
I am at a loss with an assignment. I am supposed to read from a text file, with an input of something like this: alphaproleone,stroke,42 1 and Store it into an array of structures and then output it with each word/number starting on a new line. My current code prints out only the first part, and the "a" in alphaproleone is the actual number "21".
#include <iostream> #include <string> #include<fstream> #include<iomanip> using namespace std; typedef struct drugtype { string name, target; int effectiveness, toxicity;
I have a question about one function in my program. Write a function that will replace players in a tim. New player gets in the game, and takes the place of one that leaves. Prototype of function is:
Code:
void replace(TEAM *p,PLAYER newplayer,int num)
where second parameter is new player, and the third is a jersey number of player who leaves the game.Two structures are defined as:
im trying to read employee information from a file using structures but im having problems with getting the file to open and read in the information
Code:
Write a programt that inputs (at most 50) records from a sequential file #include <stdio.h> #include <stdlib.h> struct employee // employee structure definition }
I am trying to read from a data file that has input as :
12.0, 11, 123 14.0, 12.1, 3
And I want the program to read the data from the file and then make it into an array of structures and then print that array afterwards.
Code: #include <stdio.h> #include <stdlib.h> #define MAX_INPUT 1000 int n =0; int i = 0; typedef struct { double x[MAX_INPUT];
[Code] .....
The program when run gives the following output:
Ishtiaque-Mohammed-Khans-MacBook-Pro:Comp20005 IshtiaqueMKhan$ gcc -Wall -ansi -o ProjectB ProjectB.c ProjectB.c: In function "main": ProjectB.c:59: error: incompatible type for argument 1 of "print_array"
In this string there are some numbers with a dash between them, for example, "5-10". I need to read these numbers in and then increment them. So "5-10" becomes "6-11", "6-11" becomes "7-12", etc.
So far I have:
Code: char temp[350]; //350 chars is plenty enough
// Copy the first characters BEFORE the numbers into a new char array. The next characters are the numbers. strncpy(temp, *objectData, 39); The next steps are: - Extract the two numbers from the C string (determining if the number is 0,2 or 3 digits long) and write them into two ints. I'm stuck here.
- Increment the ints
- Write the ints into the array with a dash inbetween.
I thought I'm done doing mg activity, but my professor said that we need to use a Temporary Variable for Swapping but where to put it.
Here is his activity:
Activity: Swapping Create a program that accepts a 10-element array of type int. Where the 1st user-input is stored in the 1st element of the array; the 2nd user-input is stored in the 2nd element of the array; so on so forth until the last user-input stored in the last element of the array. Your source code should be able to SWAP the values of the 1st and 10th; 2nd and 9th; 3rd and 8th; 4th and 7th; and 5th and 6th elements. It should display the values of the original and the swapped values of the array. example:
Giving the following program, how do i access the swapping function. I've tried swapp::change <int> ( a, b ) ; and it gave me 4 errors. Here's the code:
#include <iostream> using namespace std; template <typename T> class swapp
I have a program that stores health information the user inputs, one person at a time. The program works perfectly with the exception of storing the data...I need to open a file and read what health data it has in it already, if any, but store the new changes, and appended data to the array of structures, to the data in memory. All of the information is only saved back in the file once the program terminates. I'm not sure how to go about doing this, so I am also not sure what to put in the function for "Save and Exit" that the user can choose in order to exit the program.
So basically, I started out with each wizard == 1 winform, but then I found another way to do it by making the content of each wizard step a user control, then say, on initial deployment, it load usercontrol1, then when i click next, the panel hide usercontrol1 for usercontrol2 and so forth. Would it be feasible to create all usercontrols (all the wizard step) and add them in an array, then i can load them by index?
Write a program that gets a sequence of unsigned integers.the user can enter at most 100 integers.
After getting the numbers, the program allows the user to repeatedly choose one of the three options:
1. swap the location of two entries in the sequence. if this option is chosen the user is prompted to enter the two locations to be swapped.
2. print out the sequence.
3. repeatedly swap two locations in the sequence until getting back to the state before this operation started. then print out the number of swaps performed.
I have two files like original.txt and replace.txt which has equal nbr of lines in both of them.
I need to loop through these two files line by line and replace the line in original.txt to the line in replace.txt
eg :
output.txt :
1|raj|65.4|Y| 1|ramesh|65.4|Y|
replace.txt :
1|raj|65.4|Y| Cannot be processed|1|ramesh|65.4|Y|
What I need here is when reading of output.txt reaches second line of file "1|ramesh|65.4|Y|", it has to be replaced with the second line in replace.txt "Cannot be processed|1|ramesh|65.4|Y|".
1|ramesh|65.4|Y| --> Cannot be processed|1|ramesh|65.4|Y|
After the end of loop the contents of two files should be like :
original.txt :
1|raj|65.4|Y| Cannot be processed|1|ramesh|65.4|Y|
replace.txt :
1|raj|65.4|Y| Cannot be processed|1|ramesh|65.4|Y|
The files can have variable number of lines but both will have same number of lines each.
I am working on a program where I sort elements into alphabetical order and then when one is less than the other I swap them. I first did it by swapping the data but they want me to swap the nodes instead and I am having trouble doing that.
Node *add_node( Node *list, const string &s ) { struct Node *n = new struct Node; n->word = s; // copy string s to word n->next = 0;
// add node n to the list // the list should always be in ascending alphabetical order n->next = list; list = n;
I've been working on this linked list priority queue . I know that the root of the problem is in my swapUp() function (swapping the positioning of two nodes based on their priority), because the list works great up until it is called. The seg fault is not actually being caused by swapUp(), it's being caused by peekAt(), which returns the element in the node at position n. But the error does not occur unless swapUp() is called first, so that is where the issue is (I think).
There is also a seg fault being caused in the destructor, which I believe may have the same root cause in swapUp().
I have a question about one function in my program. Write a function that will replace players in a team. New player gets in the game, and takes the place of one that leaves. Prototype of function is:
void replace(TEAM *p,PLAYER newplayer,int num)
where second parameter is new player, and the third is a jersey number of player who leaves the game. Two structures are defined as:
Now I have to write a function show_exam_descending(Data d, string subCode) when I call show_exam_descending(d, "ENGL_S12") the program will execute to show all the students' exam scores in ENGL_S12 in DESCENDING order...
For this to run, I have declared a struct Data:
struct Data { string subjectCode; int studentCode; double examScore; );
For the search, I have written a function before to load all the data from the document by using pointer and dynamic arrays. It works so well. What troubles me is the way to swap the elements (i.e. examScore) of different students in struct dynamic arrays. I am able to display all of them, but don't know how to swap.
I'm about to begin work on an exercise that requires me to maintain a list of the variables inside a c source file. I'm trying to figure out how I'm going to pluck out the variable names from all the other noise. My first thought would be to count any word that isn't a keyword or other type of grammar syntax, such as parenthesis, brackets, semicolons, etc. right?