Skip to main content

Questions tagged [pointers]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
3 votes
2 answers
41 views

Why can you say the name of an array is a pointer to the first element of the array in C?

I have tried to understand why you can say the name of an array is a pointer to its first element in C. Could you please tell me if my understanding below is correct? Both the name of an array and the ...
Yuya Ito's user avatar
1 vote
1 answer
28 views

Changing the size of an array

Overall goal statement : Your goal is to create a function that removes the first and last characters of a string. You're given one parameter, the original string. You don't have to worry with ...
Captain Nemo's user avatar
0 votes
0 answers
12 views

where is the memory leak in my code?

cant find where is the memory leak here is my code // Implements a dictionary's functionality #include <stdio.h> #include <ctype.h> #include <stdbool.h> #include <string.h> #...
Omar Rehan 777's user avatar
1 vote
2 answers
62 views

Week 4 lecture: can't reproduce string != string

In the lecture of week 4 in CS50x, David illustrates how two strings can't be compared with two equal signs (==), and instead, strcmp() has to be used. I can't reproduce this locally or on CS50's IDE ...
therubberduck's user avatar
0 votes
1 answer
217 views

pset5 - speller "double free detected" when I run check 50 but program does nothing during self tests

I am currently doing Speller. I have written all the functions and the program compiles but during self testing it is printing "misspelled words" and stays stuck at a blinking cursor. It ...
Dre Johnson's user avatar
0 votes
1 answer
204 views

(PSET 4 - Recover) Why is first recovered image blank?

I am on problem set 4 recover and I have nearly completed it. I have written my code and it compiles but when I run it on the card.raw file it appears to recover all the 50 photos except the 1st one ...
Dre Johnson's user avatar
1 vote
1 answer
30 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 ...
LorenzoPeve's user avatar
0 votes
1 answer
30 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 ...
LorenzoPeve's user avatar
1 vote
2 answers
47 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: ...
Alex's user avatar
  • 11
0 votes
1 answer
127 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 ...
braninpodolski's user avatar
0 votes
1 answer
528 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 *' ...
WhatEvenIsCoding's user avatar
0 votes
1 answer
27 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!"; // ...
Matt Shirvan's user avatar
0 votes
1 answer
219 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 ...
Angela Stoddard's user avatar
0 votes
1 answer
23 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 ...
Praneeth Kumar's user avatar
0 votes
1 answer
163 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, ...
m.ravetch's user avatar
0 votes
1 answer
50 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 ...
Ciaran Egan's user avatar
0 votes
1 answer
51 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 ...
mushie2's user avatar
  • 17
0 votes
1 answer
43 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! ...
dubflicker's user avatar
0 votes
1 answer
2k 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 ...
BigTJ's user avatar
  • 3
0 votes
1 answer
382 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 "...
user3671's user avatar
  • 165
0 votes
1 answer
18 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 ...
Musical_Ant's user avatar
0 votes
1 answer
699 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 ...
Bilal Junaidy's user avatar
0 votes
1 answer
172 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) { ...
Musical_Ant's user avatar
0 votes
1 answer
42 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 ...
Fermin Bereciartua's user avatar
0 votes
1 answer
569 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 ...
Dragos Toader's user avatar
0 votes
0 answers
1k 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 ...
Gabriel Saul's user avatar
0 votes
1 answer
28 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 <...
hli's user avatar
  • 3
0 votes
1 answer
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?
Ryan Hinchliffe's user avatar
0 votes
1 answer
152 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 ...
Antwan Samir's user avatar
0 votes
1 answer
2k 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. ...
theurere's user avatar
0 votes
1 answer
897 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 ...
Charlie Chesney's user avatar
1 vote
1 answer
312 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 ...
faedx's user avatar
  • 25
0 votes
2 answers
559 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 ...
albertjlay's user avatar
1 vote
2 answers
1k 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> #...
Nikita Kokorin's user avatar
0 votes
1 answer
80 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 ...
Beyn18's user avatar
  • 21
1 vote
1 answer
104 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"; ...
Luis Alejandro's user avatar
0 votes
2 answers
123 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 ...
viet 's user avatar
1 vote
1 answer
16k views

pset1 Error: indirection requires pointer operand

Here is a snippet of my code: long long card = get_long_long(); long long *FindLength = *card; long long *FindFirstTwoDigits = *card; And here are the errors: credit1.c:8:29: error: indirection ...
yuniFlaminjo's user avatar
0 votes
1 answer
2k 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) ...
William George Bangay's user avatar
2 votes
1 answer
27 views

Using * and & both works

SPOILER ALERT THIS CODE ALREADY WORKS SO DON'T LOOK IF YOU'RE STILL SOLVING I'm just wondering why my code still works even if I change fwrite(buffer, 512,1, img); to fwrite(&buffer, 512,1, img); ...
newbie's user avatar
  • 23
0 votes
1 answer
14 views

How can I ensure I'm changing the reference, not a copy, in this C function?

I'm trying to assign a pointer to a pointer within a function. I've passed pointers in and I'm trying to make the change inside. It is not happening, however. The issue is regarding the insert ...
Krishaan Khubchand's user avatar
0 votes
1 answer
26 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 <...
Krishaan Khubchand's user avatar
0 votes
1 answer
142 views

pset5 load null pointer issue

Working through the load portion of pset5. Everything compiles, but when I run valgrind it looks as if nothing is actually loading in, with the error of "null pointer passed as argument 1, which is ...
Jake 's user avatar
  • 37
0 votes
1 answer
213 views

recover pset4 file handling

I got this code to work, but I have a few questions for my own clarification. On line 68 where I define the jpg title, why is it a single character? The actual title 001.jpg is much longer than a ...
Marie Urbina's user avatar
2 votes
2 answers
14k views

pointers and scanf : when do I use &x, *x or just x?

The following code works but why do I have to use 'x' instead of '&x' inside scanf()? ``` #include <stdio.h> #include <stdlib.h> int main(void) { char *x = malloc(sizeof(char) *...
Karin's user avatar
  • 59
0 votes
1 answer
60 views

pset1 credit various errors: incompatible pointers, undeclared identifiers

I tried to compile this: #include<stdio.h> #include<cs50.h> char get_credit_card_status(long long credit_card_number, char Luhn_check)//, char credit_card_status) { char ...
Nocxy's user avatar
  • 1
0 votes
1 answer
47 views

sizeof() syntax error with node pointer

Is there something wrong with my syntax? Won't compile, apparently because of line: sizeof(node->sprouts) / sizeof(node) above node defined as follows: typedef struct node { bool is_word; struct ...
Librarian's user avatar
0 votes
1 answer
130 views

What is correct syntax when declaring a pointer? (i.e. where to place the *?)

I'm a bit confused as to where to place the * when declaring a new pointer. For example, let's say I've made a linked list and declared a custom structure node. I've noticed when I was making ...
doctopus's user avatar
  • 119
0 votes
1 answer
76 views

SPELLER-Create Global struct definition and global struct instance

I am working on SPELLER and am stuck on the load function. I have no errors the way it's written but the problem is in this code's location. typedef struct node { ...
ndjustin20's user avatar
0 votes
1 answer
124 views

Two hash table questions

I am working through SPELLER and have a few questions. When I create a new node node *newptr = malloc(sizeof(node)); do I need to say newptr1, newptr2, newptr3 and if so what is the best way of doing ...
ndjustin20's user avatar