Skip to main content

Questions tagged [structs]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
39 views

How to merge sort array of struct while maintaining relations between int array and char array

Does anyone know how I could maintain relations between the char and int in structs while merge sorting the ints in the struct? So if I had nameandnumber[1].buffer assigned a value that used to be at ...
user21380365's user avatar
0 votes
1 answer
22 views

calling the first element in struct

I have defined an array of pairs of elements using struct and I'm trying to call (and sort) it using one of the elements (I'm not sure if element is the right term for it) for example, I have typedef ...
blueberry's user avatar
0 votes
1 answer
107 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[...
monkey king's user avatar
0 votes
1 answer
307 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 ...
Gabriel Saul's user avatar
0 votes
1 answer
435 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....
Akarsh's user avatar
  • 5
0 votes
1 answer
194 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 ...
Talim's user avatar
  • 17
0 votes
0 answers
39 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. ...
Criticalll's user avatar
0 votes
1 answer
143 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 ...
Mattiun's user avatar
0 votes
1 answer
60 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. ...
TQL's user avatar
  • 1
0 votes
1 answer
768 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 ...
Mohit Jha's user avatar
0 votes
1 answer
91 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* ...
dankthreads's user avatar
2 votes
1 answer
3k 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 ...
Karin's user avatar
  • 59
0 votes
1 answer
295 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; ...
Davis's user avatar
  • 144
0 votes
2 answers
150 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; }; ...
ketchers's user avatar
0 votes
1 answer
383 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: ...
msmith1114's user avatar
0 votes
1 answer
118 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() ...
A.Emad's user avatar
  • 176
1 vote
2 answers
171 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 ...
olafironfoot's user avatar
0 votes
1 answer
32 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> # ...
Ahmed Raza's user avatar
0 votes
1 answer
534 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'...
borker's user avatar
  • 301
2 votes
1 answer
184 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),...
Petar Petrov's user avatar
0 votes
1 answer
212 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 ...
alo129's user avatar
  • 3
0 votes
1 answer
226 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; ...
Dr.Queso's user avatar
  • 253
0 votes
1 answer
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 ...
Ryan's user avatar
  • 138
0 votes
1 answer
191 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 ...
CS50_on_the_go's user avatar
0 votes
1 answer
180 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 ...
CS50_on_the_go's user avatar
0 votes
1 answer
84 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 ...
peachykeen's user avatar
0 votes
1 answer
44 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 ...
Furrukh Jamal's user avatar
5 votes
1 answer
984 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 ...
DFATPUNK's user avatar
  • 155
2 votes
2 answers
607 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 ...
nbh's user avatar
  • 60
1 vote
1 answer
24 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 ...
Gibb Johnson's user avatar
3 votes
1 answer
6k 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 (...
UtkarshPramodGupta's user avatar
0 votes
1 answer
123 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 ...
Jared Rieger's user avatar
0 votes
1 answer
104 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(...
JV305's user avatar
  • 29
0 votes
1 answer
103 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 ...
hutmanew's user avatar
0 votes
1 answer
439 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 ...
Erin Magner's user avatar
0 votes
2 answers
54 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....
Lucas's user avatar
  • 171
1 vote
1 answer
892 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}...
Daniel Levi's user avatar
3 votes
1 answer
19k 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 ...
Christian Weh's user avatar