Questions tagged [pointers]

The tag has no usage guidance.

25 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
1
vote
1answer
48 views

References and Pointers

What is the difference between a reference variable ( eg int& ref) and a pointer variable ( int*pointer ).
1
vote
1answer
112 views

pset 4 - recover -> invalid pointer

i am trying to solve the recover issue. When I run my programm I get: * Error in `./recover': free(): invalid pointer: 0x0000000001da5200 * Aborted I don't know how to proceed. Can someone please ...
1
vote
0answers
255 views

Pset5: questions about malloc() and calloc()

One clip of my code: #include <stdbool.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #include <stdio.h> #include "dictionary.h" // Define a struct ...
1
vote
1answer
328 views

PSET5 - Issues with initialization of pointers in LOAD function

I'm still trying to debug my load function, I rewrite my code again and again but with no result... I know we need to have specific question, but now I just have so many questions. So, I'll go with ...
0
votes
0answers
48 views

Almost Done… But substrings

// Returns true if word is in dictionary else false bool check(const char *word) { //Variables bool looping = true; int hashWord = hash(word); //Create a new pointers node *head = table[hashWord]; ...
0
votes
0answers
39 views

Pset4 Recover Why does this work / what does it do?

Hi I'm working on pset4 recoverand I'm having trouble understanding something. My code does not work like it's suposed to, in fact it only creates 1 file "000.jpg" and that one isn't even readable. ...
0
votes
0answers
81 views

Pset 4 filter(less comfortable) manipulating pointers through an array

Very new to coding, so please bear with me! I've been trying to wrap my head around pointers/ addresses since Lecture 4 but I haven't been able to solve the following issue. I can make the following ...
0
votes
1answer
11 views

writting a function to display a file

in the week 4 shorts, it was told how we can write cat command from linux in c: i Wrote the following code: #include <stdio.h> include void Print_File(FILE *f) { char s = fgetc(f); while (s ...
0
votes
0answers
21 views

Pointers - Week 4 Lecture

I am having a hard time understanding the following sets of code. In the lecture, the professor alluded to how char * represents an address to a character. Additionally, he mentioned that in order for ...
0
votes
0answers
461 views

“Still reachable” in Valgrind

I have noticed on a few programs that, while none of them have any memory leaks, flag a "still reachable" message when run via valgrind. Does "still reachable" simply mean that there are pointers in ...
0
votes
1answer
18 views

Understanding pointer variables

I'm trying to understand pointer variables. I have the following sample program: #include <cs50.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <...
0
votes
1answer
843 views

Pointer error - member access within null pointer of type 'node' (aka 'struct node')

I am trying to create a function that will malloc my node pointers but for whatever reason the passed node when accessed after my function throws an error as if the node was not given memory at all. ...
0
votes
1answer
748 views

Incompatible pointer types even though they are both char*?

dictionary.c:70:20: error: incompatible pointer types passing 'char *[46]' to parameter of type 'const char *' [-Werror,-Wincompatible-pointer-types] if (strcmp(checker->word, lowword) == 0) ...
0
votes
1answer
23 views

Why am I able to insert an element into a hash tree via Main() but not via a function call?

I'm fairly certain this has something to do with pointers and the function using copies instead, but I'm not sure how...because I've inserted the pointer as a parameter for create(); #include <...
0
votes
1answer
20 views

Help needed for pointers in C

I need a bit of help for my following program which inputs a string from the user and also prompts from the user a character from that string so as to display the number of times that character is ...
0
votes
1answer
33 views

Having some issues understanding how pointers work and how to pass them to functions and use them

int* create_random_array(int n){ int arr[n]; srand(0); for (int i = 0; i < n; i++) { // Fill with random ints 1-100 arr[i] = (rand() % 100)+1; } return arr;...
0
votes
1answer
39 views

Problem with pointers, getting seg fault while indexing with variable instead of plain number

I would like to ask why is that giving me seg fault. int **a = (int**) malloc (sizeof(int*) * 3); a[0][0] = 1; a[0][1] = 2; a[0][2] = 3; for(int i = 0; i < 3; i++) { printf("%d",...
0
votes
1answer
198 views

pset4 increment pointer of type RGBTRIPLE by BYTE

In pset4, resizing an image, I decided to try out pointers and memory allocation to learn more about it, but I've run into an issue with my approach... I've created a pointer and allocated memory for ...
0
votes
1answer
15 views

*--ptr = “”; warning

I am copying one array into another using pointers, and one value in the array I have to fill in "by hand" if a certain condition happens. Please, help me to understand what shall I do to assign ...
0
votes
1answer
240 views

I've use array pointer method in pset2 (initials.c) but it return "Segmentation Fault (Core Dump) Why?

I'm working on pset2 using array pointer method, but unfortunately, the program return "Segmentation Fault (Core Dump)" I've post a picture of my code below.Can I use this method? or I have to use if ...
0
votes
0answers
55 views

pset 5 what am i missing

Im having trouble with the syntax and language for pset5, its driving me nutz. Say I have the word BAT:- OK so I have a root node. I check the root node to see if index 1 ( position 2 for the letter ...
0
votes
0answers
64 views

Initializing a variable in a struct, then in a function

It won't allow me to initialize the array to NULL in the struct in the header file: typedef struct frog { bool is_frog; struct frog* french_chef[10]; // eg = {NULL}; } frog; which I get, but ...
0
votes
0answers
138 views

pset5. dictionary lost

In speller.c we call the function to load the dictionary into memory: bool loaded = load(dictionary); where the declaration of the function is: bool load(const char* dictionary); My load( ) ...
0
votes
1answer
34 views

Issue with the cs50 c compiler

Unable to use pointer as used normally. While executing ** int a = 3; printf("%d", &a); ** This should print address of variable a. But it gives an format specifier error.
0
votes
1answer
80 views

More pointer concepts

I think that I have the basic concept of pointers pretty clear now (after considering it, reading and re-watching the course material a few times) but I still have a question. A pointer is ...