Ok, for my Sunday homework I have to find the next day of the year using structures. Now, I can get the structure to read the entered date (tested that with a simple scanf to printf entered data), but I need to get it to be able to tell that it is the end of the month and print out the next month when necessary. Here is what I got so far:
Code:
//Cameron Taylor
#include <stdio.h>
struct Date{
int month;
int day;
int year;
[Code] ....
As you can see, I am trying to use an array for the max day of each month (excluding Leap Year for now).
Where I use the entered month to = 'i'. Then I use 'i' as the position in the array to see if next.day is = to the max day of that position of the array.
I am having no compiler issues with GCC using -w or -Wall, but after entering the current day the program stops working and doesn't go beyond the input.
commiedic@localhost Project18$ gcc -o -Wall Exercise4.c
commiedic@localhost Project18$ gcc -o -w Exercise4.c
commiedic@localhost Project18$ gcc -w Exercise4.c
commiedic@localhost Project18$ make Exercise4
make: `Exercise4' is up to date.
We're writing a program in class using data structures and arrays and I'm stuck on writing a loop to find the students' highest test score. I only return the first student's ID, test score, and grade. For some reason unknown to me I'm not actually looping through all 12 or so records.
Code:
#include <stdio.h> #define MAX_ENTRIES 50 struct records { //declare my student records structure int ID; //the student's ID number int test_score; //the student's test score char grade; //the student's letter grade of aforementioned test score };
A user is supposed to enter student name, id, and grade then sort them by name, id, or grade. I managed to get it to sort by name and id correctly, but not by grade.
How do I store pointers to a struct in an array ? I am using sprintf to concatenate some values together and then output it to an array in its 1st argument. A portion of my code is shown below.
how these structures and arrays work which is why although I added alot more code than given, I sent it into my teacher and he was puzzled with my project. So I brought it back to a payroll calculator unsorted.
Sort the payroll data, and output the data to the file in order by gross pay (lowest to highest)
concepts on pointers to structures and referencing for the following two lines.
//address of the variable "struct UIP_IP_BUF" is assigned as srcipaddr uip_ds6_nbr_add(&UIP_IP_BUF->srcipaddr, //data type "uip_lladdr_t" pointer points to the address of array an "nd6_opt_llao" with size UIP_ND6_OPT_DATA_OFFSET (uip_lladdr_t *)&nd6_opt_llao[UIP_ND6_OPT_DATA_OFFSET]
# include <conio.h> # include <stdio.h> # include <stdlib.h> # include <string.h>
[Code]....
I tired changing the conditions in the for loops, but then I end up entering information multiple times and I want that to be the user's option. Do I have to change the for loops or something else? I've tried everything to get what I want but nothing works. When I print the receipt, only the last food Item that I entered prints.
I am going to be using a boolean variable to mark whether or not a specific field has had data entered into it. I figure the best way to do that is to initialize all the elements of the structures to 0. However, with strings and with the nested structure, I'm not sure how to do this.
I created a structure Vector and implement some functions to make the new defined type (vector) dynamically allocated and resized (inspired from the C++ implementation of the dynamic arrays : vector). I need to assign a structure to every vector element but I am not sure that I am doing it right:
here is the structure that I've defined:
typedef struct { void** mem; // to make this parametrizable I want the void* to point to a Structure (referenced with * a pointer) unsigned long elems; unsigned long elemsize; //element size
[Code] ....
I believe I have serious problems with pointers, values and dereferencing a pointer.
I would like to write a program that prompts the user to enter a series of client names which the program will then store in an array of structures. I'm thinking something along the lines of:
struct sInfo { vector<string> vName; float fClientHoldings; }; sInfo sClientData[100]; //create an array of structures for up to 100 client's sClientData[0].vName="Acme"; //these will be inputted by the user in my program, but I've attempted to initialize them here for simplification sClientData[1].vName="Enron";
I can't declare a structure array after I declare it. Is this true? If so, is there an alternate approach that I should be using?
I'm trying to write an object oriented application framework. The programs can be console or GUI based, but I'm having some difficulty providing a consistent interface for outputting structures. The structures will be displayed by a variable description and its value. So, for a RECT structure the output on console would look like the following.
Code: left 0 top 0 right 100 bottom 200
The numbers should be aligned next to their description. In console mode, white space must be appended to each description. In GUI, this extra process will not be necessary (some other processing might be, but it will be different).
The right way to display data in C++ is of course using a stream and defining the appropriate operator<<.
Note that endl and the spacing has been omitted. This is because GUI output will also be implemented as a stream and they do not require a carriage return or padding. Should I define a StructStream object?
After I use the structstream object to store the output as a stream how should the output be written to the screen. Should I call cout from within the stream object. Should I have two buffers, one which borrows cout.rdbuf()? Should I call printf? Should I open another standard out file and use write? Should I convert the buffer to a string which will be display by cout or a winout? what I should do?
I do this because I want to transform the .x format into xml... The "frame" data structure can contain other frames, and a name for the frame and a transformation. For example:
I know the above won't compile. But am I on the right track to implement data structures this way using linked lists? about directx, I'd like to ask is the .x format implemented with a tree structure rather than linked lists.
I have written library in c++ for c++ application. Here, data exchange between library and client through structure. This structure has 20 members ( strings, integers, reals, pointers).
In some flows, library needs few members should get filled in the structure. for ex, application filled 3 integers information and passed to structure. But, in memory, whole structure is occupied.
I think, If library provides functions for every combination, then it would end up with lot of functions. I want to avoid that.
How to optimize data exchange between client and library? ( number of members may be filled sometimes 1, 2, 3, .. 20)
I need to translate a C program to C by making variables in structures private(no classes yet!) and putting public inline functions. There's a good chance that I have much more problems with my code than I'm asking right now, but I have 4 spots that I'm currently stuck in and can't access properly.
My structures:
Code: struct Container { private: int count; char** lines; int nlines;
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: