C :: Filling Structure Client / Storing Different Instances In Array
Mar 31, 2013
Here is what I have going on.
Code:
struct client {
char firstName[stnd];
char lastName[stnd];
long ID;
char email[stnd];
float funds;
float wager;
}
typedef client...I would like to have these fields filled with this function below and stored in an array... Basically Multiple users and this is my function for it, if I can get it to work proper -.- .... I don't get syntax errors but I do get warnings
Code:
void getct(client *cl, int *pclientCounter) {
char input[buff];
char *pinput = NULL;
int typef = 0;
int lengthf = 0;
}
[code]....
View 3 Replies
ADVERTISEMENT
Feb 20, 2015
I have a structure
struct Wine
{
string wineName;
int vintage;
int rating;
double price;
};
how can i store the file data below in an array with the structure type???
Dow Vintage Port ;2011;99;82
Mollydooker Shiraz Carnival of Love ;2012;95;75
Prats & Symington Douro Chryseia ;2011;97;55
Quinta do Vale Meão Douro ;2011;97;76
Leeuwin Chardonnay River Art Series ;2011;96;89
View 1 Replies
View Related
Sep 3, 2013
template <typename T> struct avl_tree {
T data;
int balance;
struct avl_tree <T> *Link[2];
static int (*comp)(T, T);
};
In main, I have a function like so:
int compare(int a, int b) {
return ( a - b );
}
Now how do I assign the function pointer in my avl_tree class to the compare function?
I did this:
int (avl_tree<int>::*comp)(int, int) = compare;
But I got the compiler error:
Tree_Test.cc: In function ‘int main()’:
Tree_Test.cc:27:42: error: cannot convert ‘int (*)(int, int)’ to
‘int (avl_tree<int>::*)(int, int)’ in initialization
View 12 Replies
View Related
Aug 5, 2014
I'm having trouble reading my data from a .txt file into a structure of the format shown in my code. I've made my student database in the program below based on user input and I didn't have a problem with that, but now it's come to input from a file it's making it difficult.
My three tasks are:
(1) A table containing 1 row per student, containing the student ID number and all of the student's marks.
(2) Another table, containing 1 row per student, containing the student ID number and the average mark obtained by that student.
(3) The average mark for each subject.
The assumptions to be made are: The student ID can begin with a zero, and should therefore be read in as a string.The test data will contain 20 students but the program should be able to deal with up to 100 students.Assume there are no more than 4 different subjects.
So based on the first assumption I've arranged the data in the file in an order in which the student ID begins with a zero:
003953 Computing 38
003953 English 88
003953 Mathematics 29
003953 Physics 83
073241 Computing 63
073241 English 99
073241 Mathematics 32
073241 Physics 73
...for twenty students, 80 lines of data. Now, on the assumption they must be read in as strings, this is what's making it tricky to store in the structure because, I've got 80 ID numbers but 20 repeat themselves 4 times. Once I've got this data in the structure below the tasks I won't have a problem with because I can just base it on a user input program but the data's already stored instead.
Below is my code for user input associated with task (1). In this example the IDs are stored as ints but for the file they will be strings. It compiles fine, displays the data as shown in the assignment sheet, but I don't know how to get the data into my structure. I can store the data in a structure of three arrays using fscanf() no problem, but it's not very "workable" for what I need to do with it.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
[Code].....
View 11 Replies
View Related
Mar 24, 2013
So here is the C code:
Code:
#include <stdio.h>
int main(void)
{
//2D Array
int array[2][2];
int number = 1;
}
[code]....
The array is not filled incorrectly for some reason, more specifically the first row.The first two cycles of the for loop seem to work correctly. One if the bugs seems to occur on the third. when array[0][2] is filled with number 7, for some reason array[1][0] changes it value to 7 as well.
View 2 Replies
View Related
Jun 25, 2013
I have this snippet :
Code:
#include<stdio.h>
#define LEN 3
int main(void)
{
int a[LEN] = {0} , b[LEN] = {0} , i = 0;
[Code] ....
/* OUTPUT :
a[0] = 2 , b[0] = 1
a[1] = 0 , b[1] = 3
a[2] = 0 , b[2] = 0 */
The problem is some elements of the array would be remained zero and unused. Is there any solution about this wasting of memory?
View 7 Replies
View Related
Mar 24, 2013
Assuming that we have :
Code:
int arr2d[rows][columns] ; // Not valid syntax of course ... let be arr2d rows * columns size
for(int i=0; i<rows; i++)
for(int j=0; j<columns; j++)
arr2d[rows][columns] = some_value;
What is the complexity? I believe O(n) and not O(n^2) on this case because if you have 3*3 size you would put 9 elements (from 9 elements input of course)... for each input you have one insertion and that is the meaning. Same as 4*4 size 16 input times 16 insertions .. or 5*5 and so forth...
View 8 Replies
View Related
Oct 6, 2013
What am I doing wrong here.
Code:
#include <stdio.h>
#define N 25
int main () {
int s,min,sec,total,mins;
float speed,splits[N];
[Code] ....
View 2 Replies
View Related
Mar 2, 2013
I am trying to do binary filling. This is the Constructor code, you will see a couple of integer arrays:
Doc::Doc ( int useridValue , string firstnameValue , string lastnameValue , string deptValue
, int dayinhourValue[] , int dayinminValue[] ,int dayouthourValue[] , int dayoutminValue[]
, int timeperpatValue , int appValue[] , int applimValue[] ) {
setuserid(useridValue);
[Code] ....
it gives an error:
void Doc::setdayinhour ( intdayinHOUR[] ){
for(int i=0;i<7;i++) {
dayinhour[i]=dayinHOUR[i];//highlighted area
} }
I am using this code for filling:
void main () {
Doc r;
ofstream outDoc("docdata.dat" , ios::out | ios::binary);
if (!outDoc) {
cerr << "File Could Not Be Opened" << endl;
[Code] ....
View 5 Replies
View Related
Feb 8, 2015
I am trying to make kind of a messenger using Socket/Network Programming
My program should allow clients to register or sign in, after they are signed in they should see a list of the other signed in people whoever I select from that list I should be able to implement using multiple threads as well.
I have done this much:
User.txt file
ahsan,1234
bilal,1234
pappu,1234
babu,1234
Client.c
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
[code]....
Now issue is in this code I am getting error SEGEMENTATION ERROR, CORE DUMP
View 5 Replies
View Related
Oct 5, 2014
I am currently working on writing a word search program. However, I am stuck on reading the used input into the 2-D array. The code I've posted below is only dealing with the user input (I'll work on the word search part once I know i am correctly reading in the user input). I know the coding is bad practice with the use of hexadecimal, and getchar() ect. But I am currently using a microblaze microprocessor and this is just the way microblaze can interpret the information. As for the infinite while loops...that can be changed just trying to figure out how.
My question is how could I change my code to correctly read in the user input into the 2-D array?
Code:
#include "platform.h"#include "xparameters.h"
#include <stdlib.h>
#include <stdio.h>
#define MAX 20
int main() {
char grid[MAX][MAX], word[30];
int i, j, arr[2],num;
[Code] ....
View 10 Replies
View Related
Jan 12, 2013
Just trying to fill a dynamically allocated array with values then I want to print out the values using pointer method:
#include <iostream>
using namespace std;
long * extend_arr(long int arr[], long int length, long int val) {
long * array2 = new long [length + 1];
for (int J = 0; J < length; ++J)
array2[J] = arr[J];
[Code] ....
When this runs, I get an array with random numbers in it. For example, just trying to print the first value in *Block gives me random numbers each time. What is wrong with this as to why it is not holding the right values?
The extend_arr works perfectly fine, because when I try to access the values in the array using indexes (arr[0], arr[1], etc) it shows the right output, but using pointers does not. How can I make it work?
Output:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 134561 23 29 640 112
As you can see, the primes end at 97 but it just keeps printing more
It now prints the correct values in the function if I set the last value in the array to 0. arr[length] = 0;
Now if I wanted to print the values in the array within main, why is that not working?
Nvm, I just changed the void function to return a pointer to an array.
View 2 Replies
View Related
Dec 25, 2014
int firstarray[12][7] = { };
double firstClass(int airplane, int seats, double price)
{cout<<setw(60)<<"---------------------...
cout<<setw(60)<<"You are in **first class** booking screen
[Code] .....
The thing is, The first 2 rows having 7 columns like this:
0000000
0000000
User gives an input of seats reserved, for example user inputs 3 seats, then the program should give output like:
1110000
0000000
I will not ask any specific seat but put assign seats randomly where available.. How to do it?
View 5 Replies
View Related
Sep 2, 2014
I am trying to fill an array with blank spaces and instead i get the number 32 over and over, i think this is the ANSI code for that character. how do i get the character itself?
char values[max];
for(o=0;o<=max;o++)
{
values[o]=' ';
printf("%2d ", values[o]);
}
printf("
");
View 1 Replies
View Related
Jul 26, 2012
Project compile successfully but console turn off with "Windows " with error doesn't print or get anything
Code:
#ifndef Point_HPP // anti multiply including gates
#define Point_HPP
#include <string>
#include <iostream>
#include <sstream>
#include <cmath>
[Code] .....
View 2 Replies
View Related
May 17, 2013
I wrote a Simon game, and wanted to save the top 10 scores. I was working right, until I decided I wanted to still be able to read the file if someone enters a name containing spaces. Now, the results aren't right.
void FillScoreList(string Simon_Names[], int Simon_Scores[]) {
ifstream Simon_HiScores("Simon_Data.txt");
if (Simon_HiScores.is_open()) {
for( int x=0;x<10;x++){
[Code] ....
Even without trying to read names with spaces, I'm getting
dad 1
0
340176
0
... either a long number or a zero. No names
View 4 Replies
View Related
May 17, 2014
#include <iostream>
#include<fstream>
int decryption(int);
int multiply(int,int[][2]);
using namespace std;
main(){
int n;
ifstream inFile;
inFile.open ("out.txt");
[Code] .....
I was trying to store numbers read from a text file into 2D array but I am getting the error above.here is where the error occurs:
line 33: cout<<m[i][j]<<" ";
View 4 Replies
View Related
Jul 31, 2013
Take for example two arrays.
int A[2][2][2] = { {{1, 2}, {3, 4}},{{ 5, 6}, {7, 8}} };
int B[1]
I want to store the entire array "A" into B[1]. Is it possible?
View 2 Replies
View Related
Mar 27, 2013
I am having trouble storing strings into an array. Basically I have a console program where it has an option. This is just an example;
Code:
char name[max];
char listofnames[maxname];
int counter;
....
printf("Add names
");
And how can I print it?
View 9 Replies
View Related
May 4, 2013
So i have a program with the structure
Code:
char record[20];
typedef struct{
int id;
char title[20];
char subject[20];
char faculty [20];
int level;
char fname[25];
}report;
int recno,i;
report list[100];
I need to store the hundred records into a file. What are the functions and elements i should use/introduce.
View 2 Replies
View Related
May 2, 2013
How do I go about storing info to an array of class?I need to do something like this:
info[count] = ReadNameRating(n, r);
Where info is an array of my own class and ReadNameRating reads the name and rating which is two of the variables handled by that class.
View 2 Replies
View Related
Sep 27, 2013
I have a base class Building. Then come its children classes - Commercial Building and Residential Building. The third level is composed of Apartment and House classes, both inherit from Residential Building.
I need to create an array of 20 elements that will store info about all these different types of buildings(Commercial Building,Residential Building,Apartment, House). How should I proceed?
View 5 Replies
View Related
Oct 2, 2012
I want to create filenames such as Query.student.1.bin and save them in an array. I have no problem when I don't include a "." between student and number "1" but as I add a "." there my code does not run. ( it does complie but crashes during the run)
string *filename_str;
filename_str =new string[Number_X_Axis];
for(i=0;i<Number_X_Axis;i++)
filename_str[i]="Query."+Table_Name+"."+convertInt(i)+".bin";
View 2 Replies
View Related
Jan 30, 2013
I am creating a program and am having trouble with one part. The input file looks like:
Code:
2
3
Bill Jeff Steve
Linda Brittany Jessica
3 1 4
2 1 9
8 3 7
6 4 9
4 8 9
6 9 4
Where I am stuck is putting the numbers into the string array. For example, Bill's scores should be set up as Bill's scores should be set as
Code: bill_score = {3, 1, 4}
and when this code is ran
Code:
for (i=0; i<3; i++) {
printf("%s - ", men[i]);
[Code].....
View 4 Replies
View Related
Dec 16, 2014
Code:
for(int i = 0 ; i < SIZE ; i ++)
{
scanf("%d" , & selection[i]);
srand((unsigned) time(&t));
draw[i] = rand() % 50; //feeling could be a problem with this line of code :::::
}
is it possible to do this. i am trying to get 6 different numbers stored into 6 elements of an array . this is the piece of the code i think there is a problem with. ie my program scans the numbers and then crashes at this point so think it could be something to do with the commented line?
View 2 Replies
View Related
Sep 12, 2013
Is something like this possible and if not how can I make this work?
fscanf(in, "%d %d %d", &i, &x, &arr[i+x]);
View 4 Replies
View Related