Questions tagged [structs]
The structs tag has no usage guidance.
37
questions
0
votes
0answers
12 views
CS50 pset 3 Plurality - Works until…Segmentation fault, and not enough vote prompts?
Task is to have people type in their votes for the candidates given in the command line, then the most voted candidate wins. I only need to and am allowed to write code for the last two function ...
0
votes
1answer
76 views
Trouble modifying elements of an array of candidates in Plurality
I'm working on Plurality of pset3. I've run into an issue modifying the vote count of each candidate. I've isolated the problem in the full program below. It appears that
candidate zero = candidates[...
0
votes
1answer
239 views
check50 claiming pairs are sorted incorrectly
On Problem Set 3, check50 has flagged my program as not having sorted the pairs correctly. However, the pairs array appears to be sorted in every case I've tried. I used insertion sort and had ...
0
votes
1answer
117 views
How does RGBTRIPLE differentiate between the 3 bytes it reads from input file and assign them to rgbt blue, green and red?
sorry if the question is confusing, but i completed the whodunit problem in pset3 and my doubt was that in the following code:
// iterate over pixels in scanline
for (int j = 0; j < bi....
0
votes
1answer
46 views
Declaring a typedef struct for linked list
In Lecture 4, David uses this to declare a node struct:
typedef struct node
{
int n;
struct node *next;
}
node;
However, in shorts after Lecture 4, Doug explicitly tells us that when ...
0
votes
0answers
38 views
I don't understand how to change header info and how it is implemented
I don't understand how the new image will implement new data i imput in like new_biWidth or new_biheigh. I added this new variables in bmp.h and I asigned to them same tipes of data like the old ones. ...
0
votes
1answer
123 views
Pset5 with linked list: head node creation
I am having some headaches about pset5.
Before tackling hashtables and tries, I have been trying to solve the problem with a single linked list to make it simpler. To do this I have defined a couple ...
0
votes
1answer
42 views
Last word of dictionary file replaces all the nodes in node bucket
Currently I am working on the load function using a hash table with singly-linked list. I have tested the create(), insert(), and find() function in a separate file and they work as expected.
...
0
votes
1answer
272 views
Problem accessing the last element of the array
I've decided to implement the load function using trie, which I've defined as
typdef struct trie
{
struct trie letters[27];
bool isWord;
}trie;
then later, when I try to ...
0
votes
1answer
87 views
Pset5 Dictionary C Struct Array Call In Load Function Issue
I've defined the struct as following:
// Node struct
typedef struct node
{
// Node value
char word[LENGTH + 1];
// Node Pointer to next value/node
struct node* ...
2
votes
1answer
2k views
Pointers and arrays, don't understand the relationship
I made two structs, they are very similar. The first one is a node and the second one, called hash, only contains a pointer to a node. In main I've made pointers to allocated memory for them. newNode ...
0
votes
1answer
276 views
Pset 4 - Help understanding structs in copy.c
Trying to understand copy.c has been a pain for me so far. I feel complete lost at how the structures from the helper file work in copy.c An example:
Helper file:
typedef struct
{
WORD bfType;
...
0
votes
2answers
25 views
Error when assigning a structure to another of the same type
It seems like the following should copy t1 into t3 (that seems to be what the documentation I have read suggests)
#include<stdio.h>
struct test {
int a;
char* name;
struct test* b;
};
...
0
votes
1answer
268 views
typedef struct declarations?
In Week 5 Linked Lists/etc... are talked about.
In the stacks/queue's the structs are defined like:
typedef struct
{
int size;
int capacity;
}
stack;
whereas he defines the "node" struct as:
...
0
votes
1answer
74 views
I am getting an unexpected sizeof() error
I am using a BIT filed varibale in a struct to Modify the size of the data type. I need this struct to be exactly equals 1. According to my calculations it is equal to 10 but when I use the sizeof() ...
1
vote
2answers
158 views
in pset4, resize: How does the structs declared in 'bmp.h' know which bytes to get the data from?
I managed to complete the pset4/resize, but am having difficulty understanding the concept behind how it works. That gap is showing up in my attempt at pset4/jpg.
fread as far as I know doesn't tell ...
0
votes
1answer
22 views
This code is written as per video in CS50 week 4 but it is not working
I have written this program as described in Walkthrough week 4 in structs 0 but it is not working, Kindly point out the mistake Thanks a lot.
# include <stdio.h>
# include <cs50.h>
# ...
0
votes
1answer
277 views
De-referencing an array of pointers to structures
Drowning in trying to understand how to dereference pointers in a linked list here...
Let's say I have a simple struct, called entry, which has char * name and int ID entry* next fields.
If I know I'...
2
votes
1answer
130 views
pset4: Order in structs and “word-aligning” by clang
I was just reading the pset4 text and can't get my head around this part:
As this figure suggests, order does matter when it comes to structs'
members. Byte 57 is rgbtBlue (and not, say, rgbtRed),...
0
votes
1answer
200 views
pset 4 Recover creates 50 corrupted or mainly grey images
I wanted to try using malloc and a BUFFER structure of 512BYTES for this exercise with the intention of creating a file if the 4 signatures of a JPG are detected and fwriting the struct of 512B into ...
0
votes
1answer
133 views
Can I create an element of arbitrary size in a STRUCT?
I'm working on recover.c.
It seems like a tidy solution to eliminate fseek calls would be to create a struct like the following:
typedef struct
{
BYTE first;
BYTE second;
BYTE third;
...
0
votes
1answer
103 views
Trouble Interpreting Linked List Sample Code - PSET5
I'm having trouble interpreting the code for a linked list of students passed out as preparation for pset5, and would like to know if someone could explain what I am missing.
The structs are as ...
0
votes
1answer
134 views
Want to make sure I understand struct, malloc, and pointers and how they relate to each other
Sort of related to PSET4 resize, but actually want to make sure I understand this in general.
So at first I just declared a struct BITMAPINFOHEADER called "new_bi" and dealt with it while avoiding ...
0
votes
1answer
156 views
PSET4 Resize: How do I copy a struct?
I was wondering what the best way was to copy a struct. Most of the info I was able to find online was about just copying the pointer to the struct. But what if I wanted to make a complete copy of a ...
0
votes
1answer
83 views
Pset4 Resize: Am I on the right track here? None of my code seems to be working. Any advice would be great!
As the title suggests I am struggling quite a bit with this problem. I have copied my code below. It compiles, but none of it seems to be working. I feel like I am on the right track but may be ...
0
votes
1answer
40 views
Structures related question
ok after completing pset3 I am about to start pset4 im on week 5 of lectures, before going into the pset4 i thought of practice a bit about structures and wrote this code. I idea was to save the ...
5
votes
1answer
966 views
Pset5: Misunderstanding tries and method to assign letter to an array inside a struct
Before posting, I've searched a lot here and there on the Internet to find the answers to my questions myself and I did code something that eventually works.
My issue is that I've re-rewrote some ...
2
votes
2answers
320 views
Pset4: How does fread add properly to the struct?
In Problem Set 4 we're given the copy.c and bmp.h files. On line 47 the fread() function is called with the arguments, &bf, sizeof(BITMAPFILEHEADER), 1, and inptr. I understand what each of these ...
1
vote
1answer
19 views
Bang and Structs
I was hoping someone could clear this up for me, the searches seem to be ignoring the bang.
If I put
while(!NULL)
{
// do this
}
would that be equivalent to saying continue doing this while the ...
2
votes
1answer
5k views
Why can we pass a struct variable to a function by value but not an array?
As taught we can pass a whole "struct" by value to a function but we can't pass an array by value. Why?
And, what if the passed struct contains an array as a member? Would it get passed completely (...
0
votes
1answer
53 views
Struct array not assigning value being set
I am currently trying to develop a neural network program for pattern recognition. The basis for the neuron are sigmoid neurons, and the network has three layers. At the moment I am trying to develop ...
0
votes
1answer
91 views
fread not updating the values in my struct in recover pset4
I created a struct
typedef struct
{
BYTE buffer[512];
} __attribute__((__packed__))
BUFFER;
then I try reading card.raw and writing to a new file in a while loop
fread(&photo, sizeof(...
0
votes
1answer
95 views
Question of inputing an array of char
I created a struct, it's elements are all char*. When it comes to asking inputs for these char*, i don't want to use GetString(), instead i tried scanf(). The output is definitely wrong.
Here is my ...
0
votes
1answer
196 views
Am I creating an array of pointers or an array of structs?
I've read an answer to a similar question about
node* new_node = malloc(sizeof(node));
and how it allocates memory for the pointer plus all the data contained within the struct as it was declared
...
0
votes
2answers
51 views
placement of structs in code
Stylistically is it possible to declare structs on top followed by their definition after int main? I tried doing it the same way as one would declare functions before main but it doesn't seem to work....
1
vote
1answer
612 views
typedef struct vs. struct
Is there a practical difference between:
typedef struct
{
float x;
float y;
} Point;
Point origin = {0.0, 0.0};
struct Point
{
float x;
float y;
}
struct Point origin = {0.0, 0.0}...
3
votes
1answer
15k views
How to free a nested struct?
In preparation for my final project, I am writing a C program that handles task lists. It utilizes a nested struct. For every line it reads from a file it creates a struct of type task. Each task then ...