Questions tagged [pointers]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
2answers
33 views

Blur PSet4 (Filter) - Compilation errors passing reference to the image[height][width] array in helper function using pointers

I'm having a brainfart wrapping my head around the use of pointers when trying to pass a reference to the image 2D array in a helper function that I created to assist in the blur effect. Here's blur: ...
0
votes
1answer
13 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
1answer
10 views

pointers and addresses

int m=10; int *ab=&m; printf("address of *ab:%p\n",&*ab); printf("adress of ab:%p\n",&ab); output: address of *ab:0x7ffd85fddefc adress of ab:0x7ffd85fddf00 i ...
0
votes
1answer
27 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 ...
1
vote
1answer
11 views

Pointers Memory Allocation

Here I have a user-defined structure "person" that stores two pointers one for the name and one for the phone number. I create an array people of length 2 of type person. Each of the ...
0
votes
1answer
20 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
23 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 ...
18
votes
2answers
50k views

Difference between char and char* in c

suppose we declare two variable char s[]= "hello" char* p = "hello". what is the difference between these two?
0
votes
1answer
35 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
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
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
9 views

Week 4 Memory - Swap

Does the = (assignment) get me a copy of the content or points me to the same location in memory? For some reason, I end up thinking that what the code does is not setting y = 44 in a separate memory ...
1
vote
1answer
50 views

References and Pointers

What is the difference between a reference variable ( eg int& ref) and a pointer variable ( int*pointer ).
0
votes
1answer
40 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",...
1
vote
1answer
121 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 ...
0
votes
1answer
82 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 ...
0
votes
1answer
29 views

PSET4 Blur not passing Check50

My code seems to work (when visually inspecting output files), but Check50 does not pass it. I'm struggling to understand what is causing this issue despite having repeatedly read over the code and ...
0
votes
1answer
1k 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
243 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
1answer
991 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
232 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 ...
1
vote
1answer
330 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
1answer
15 views

Why is the reference variable for dynamically allocated memory lower on the stack?

#include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { int n = 5; char str1[n]; char *str2; char str3[] = "World!"; // ...
0
votes
1answer
48 views

incompatible pointer types error

I'm working on lab5, inheritance, and I'm trying to decipher why I'm getting this error when trying to compile: inheritance.c:52:32: error: incompatible pointer types assigning to 'struct person *' ...
1
vote
1answer
7k views

C: Vigenere - incompatible pointer types passing 'char **' to parameter of type 'const char *

I'm trying to iterate repeatedly over key (a word) which the user inputs on the command line. This keyword is used to encipher a word which the user inputs when prompted by the word 'plaintext'. I ...
0
votes
0answers
11 views

According to CS50 Lecture 4 on Memories, my code should not be able to compare two strings and print“same”. But it does print “same”. Why?

Was expecting it print out "different" since I've created 2 different variables and stored the same values MANUALLY TYPED OUT. According to lecture 4, strings are pointers and when compared, ...
0
votes
1answer
30 views

PSET2 Caesar - Stuck at 'isdigit' step: Do I need to learn about pointers, or is something else going on?

Here is what I am attempting, and my errors. I am gathering that I am not grasping the "array of strings nature of argv[], and since I am following along with the material from class, I am pretty ...
0
votes
1answer
31 views

PSET4 filters helpers.c

I need some help with pointers, mostly. I've malloc'd a BUFFER pointer to the struct data type RGBTRIPLE. Though I can't access its properties. // Reflect image horizontally void reflect(int height, ...
0
votes
1answer
45 views

CS50 Pset4 Logic Problem

I am 3 days into PSET 4 Recover. In PSET 4 we are supposed to create a program which inputs a memory card and scans through that memory card for the signatures of lost JPEG files. Once the header of a ...
0
votes
1answer
43 views

I know that my recover is wrong, but I'm not sure what steps to take-

I 'm getting a segmentation fault for my recover code. I know that it's wrong, and I think that this boils down to me not really understanding how to apply pointers/file functions. Maybe you could ...
0
votes
1answer
36 views

pset4 recover - how can I get last few bytes to JPG

I've finally gotten recover.c to the point where it compiles. When I run it, it gives me this error message: munmap_chunk(): invalid pointer Aborted But it also generates all fifty of the pictures! ...
0
votes
0answers
50 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
1answer
100 views

Pointer passed as argument, then suddenly goes null

In the main method I declare a character pointer pCharacter. I pass this variable to the setCharacter method and assign it an address and a variable gets assigned to that address. From what I ...
0
votes
2answers
116 views

Segmentation fault in recover pset4

I am working on recover in problem set 4. However, after trying out different stuff, the code itself compiles but I get a segmentation fault and the outcome is only one jpg file called 000.jpg. I am ...
0
votes
1answer
41 views

Confusion about comparing strings and int/char

This question concerns variables, pointers and addresses as addressed in Lecture 4. I understand that strings are not "real" in the way that integers and characters are, and are just defined as "...
0
votes
1answer
111 views

What does a pointer to a file really represent?

I have a question regarding file pointers (i.e FILE *). I am having a hard time understanding conceptually what this represents in terms of its memory. When the concept of files was introduced in ...
0
votes
1answer
43 views

Replacement of string with char* in any general case

Take a simple program where i want to count the number of vowels in a string, this i've easily implemented using string.h. But when i try that with char*: #include <stdio.h> int main(void) { ...
0
votes
1answer
29 views

Pointer Initialization and Free, Help!

If you initialize a pointer (trav) and assign it another pointer, should you and what happens if you free trav? thank you! node *table[N] = { NULL }; trav = table[i]; Also, should malloc be called ...
0
votes
1answer
305 views

Speller Valgrind leaks bytes + error: munmap_chunk(): invalid pointer error in C

Check50 gives me the munmap_chunk: invalid pointer - it seems I am not copying something right with strcpy. Valgrind gives me: LEAK SUMMARY: still reachable: 608 bytes in 2 blocks ==2864== 56 bytes ...
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
0answers
847 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
14 views

How do I change the value of “a” via “b”?

e.g. Input: int a = 1; int b = a; b = 5; printf("%i \n", a); Output: 5 I have tried writing things like int* b = &a; b = 5; However i cant change b into an integer from a pointer?
2
votes
2answers
334 views

Pointer Concepts

I am problem set 6 and very confused by the use of pointers. Please tell me the difference of these things first? What is the difference between char word[length] and char *word = malloc(sizeof(char) ...
0
votes
1answer
34 views

the difference between string pointers and int pointers

why does the compiler act in a different way when a string is initialized or declared than it does in case of an integer pointer ? i mean we do that char *x = "cat" not char* x = &(of ...
0
votes
1answer
894 views

Pset2 Vigenere: Pointers/Function Question

I've been having major trouble with Vigenere. I've worked on it every day for the passed two weeks and each day, I solve one problem but encounter another. I was able to get the program with the ...
1
vote
1answer
148 views

vigenere output “incompatible pointer types”

I'm trying to solve pset2 vigenere, but I'm having some troubles. I'm using two functions to adapt the key to the text and then to apply the cipher. When I run the last function, I can't get any ...
0
votes
2answers
395 views

How to convert char to integer? PSET4

int main(int argc, char *argv[]) //Remembers n int n = *argv[1]; I'm trying to access the value n as an integer. However, when I do this, n stores the ASCII code for the number (I think!). I have ...
1
vote
2answers
780 views

Printf doesn't print whole string “11111”

String a, that is a pointer, contains 5 1's, but printf outputs only one 1. #define _XOPEN_SOURCE #include <unistd.h> #include <stdio.h> #include <stdlib.h> #...
0
votes
1answer
69 views

pset5 (trie) valgrind memory leak

I'm having trouble with the last step of pset5, valgrind. When I run it with the test text I get: Looks like you're trying to access 8 bytes of memory that isn't yours? Did you try to index into an ...
1
vote
1answer
33 views

Pointers to strings

I have yet another question regarding pointers to strings. I want to know why this code works fine, and by that I mean that it can change the char d to the char Q. char Name [] = "Andrew B. Mayfair"; ...