Questions tagged [pointers]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
25 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
27 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
20 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
1answer
23 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
0answers
38 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
61 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
7 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
14 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
36 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
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
1answer
25 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
75 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 ...
0
votes
0answers
325 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
16 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
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?
0
votes
1answer
18 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
747 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
877 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
98 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
294 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
454 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
67 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"; ...
0
votes
2answers
102 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
4k 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 ...
0
votes
1answer
640 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) ...
2
votes
1answer
25 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); ...
0
votes
1answer
8 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 ...
0
votes
1answer
22 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
100 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 ...
0
votes
1answer
158 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 ...
0
votes
1answer
4k 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) *...
0
votes
1answer
55 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 ...
0
votes
1answer
22 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 ...
0
votes
1answer
20 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 ...
0
votes
1answer
60 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 { ...
0
votes
1answer
76 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 ...
0
votes
1answer
80 views

pset4 whodunit can't understand the infile pointer

In this whodunit copy.c the input filenames and output filenames are entered as command line arguments but I couldn't understand that How does inputting the file name will point to the file. // ...
0
votes
1answer
89 views

Pointers: What is the difference between char * <name> = … and char* <name> = … in assignment operations

In problem set 5, there are these two lines of code. char* dictionary = (argc == 3) ? argv[1] : DICTIONARY; ... char *text = (argc == 3) ? argv[2] : argv[1]; Both of theses operations seem to define ...
0
votes
1answer
152 views

difference between int* and char*?

Why this code not is not compiling int *pkk = 5646; printf("%d\n", *pkk); printf("%d\n", pkk); but this works perfectly char *sp = "Hello"; printf("%s\n",sp); printf("%c", *sp);
1
vote
1answer
353 views

Difference between s and *s in pointer

This code print Only first letter i.e 'H' #include <stdio.h> int main(void) { char *s = "Hello"; printf("%c\n", *s); } But this return 'Hello' #include <stdio.h> int main(void)...
0
votes
1answer
18 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 ...
1
vote
1answer
236 views

Arrays of Pointers - implicit double dereferencing

Good day people! The context is resize program in problem set 4, however, the question is general. Following is how the main function begins for the relevant program: int main(int argc, char *argv[])...
0
votes
1answer
651 views

Null pointer problem inside check function of pset5

I've been working very long on this and I can't find a way out. I've created a node struct and a hash struct. Like this: typedef struct node { char value[45]; struct node* next; }...
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
131 views

Linked lists & pointers

In pset 5s walkthrough, the node struct is defined like this: typedef struct node { int value; struct node* next } node; And when we then use the cursor -> next statement, to jump to the ...
1
vote
1answer
47 views

References and Pointers

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

Pset 5 Speller Check/Load Entries in Hashtable All Have Same Memory Address

I'm working on speller and am having problems with my check function. I thought that my load function is working right, I'm not getting any errors or memory leaks. But, when I look in my hashtable ...
5
votes
1answer
1k views

PSET2: CRACK vs POINTERS

SPOILERS (maybe) Hi, I have just started working on crack. I have no previous experience, at least not too much but I'm trying to grasp the logic behind this and it seems my biggest issue for this is ...
0
votes
1answer
52 views

Declaring an array of structure pointers

How to declare an array of structure pointers? I need to create a collection of linked list. Is it same as declaring ordinary arrays? If