Questions tagged [pointers]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
106 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
181 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 ...
1
vote
1answer
5k 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
57 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
26 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
37 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
63 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
87 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
82 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
104 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
160 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
376 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)...
1
vote
2answers
122 views

3 days failing to get bubblesort working .. devastated :(

i am a beginner, i got linear search working quite fast.. but then total stuck. i tried to write function test, that gives me some random numbers and sort them. I watched all the videos and thought ...
1
vote
1answer
270 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
654 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; }...
0
votes
1answer
132 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 ...
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
229 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 ...
0
votes
1answer
56 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
0
votes
1answer
1k views

Pset4 - Recover (usage of sprintf)

When I am working on Pset4 - Recover, I realize I do not understand the concept of array and pointer. Although I finally worked it out, I would be very grateful if you guys can explain the following: ...
0
votes
1answer
2k views

Error with comparison between pointer and integer

I'm having some problems with making the vigenere assignment from CS50. I get many errors about my comparison between pointer and integer, how can I avoid this error? I also have some problems with ...
0
votes
1answer
346 views

pointer for function using global variable

I understand why passing value in a function does not work as main function will not have access to changed value (change takes place in the stack frame of called function However if I declare ...
0
votes
1answer
32 views

Week 5 - Speller. Instance remaining as NULL after setting inside function

I create an instance of a struct, wordTree, at the base level of my dictionary.c file. When the load function is called, the intention is that this instance gets created, and "branches" are then added ...
1
vote
1answer
30 views

How to use a pointer?

I wanted to pass the value of argv to a function but it is showing error so can any body hellp me my function void init(void) { // TODO int size = *dim; int row; int column; int ...
1
vote
1answer
7k views

incompatible pointer to integer conversion

incompatible pointer to integer conversion link to my file https://ide.cs50.io/rahulatrkm/ide50#openfile-x I was geeting message like this clang -fsanitize=integer -fsanitize=undefined -ggdb3 -O0 -...
0
votes
1answer
134 views

unable to use a 2d array via function

#include <stdio.h> void array(int *ar,int row,int col); int main(void) { int a[][2] = { {1,2}, {3,4}, {5,6} }; ...
1
vote
1answer
105 views

pset4 resize file header question

I'm struggling a bit with pset4 changing the header info. I feel like in principle I know what I'm supposed to do but struggling a bit with syntax/pointers? Following the resize walkthrough, I know ...
0
votes
1answer
60 views

PSET6 - load function - 1 file is not loaded (the jpg)

PSET6 is a huge challenge. I have juste passed the first checked and I am trying to understand why my load function is not 100% correct. This is the feedback of the second check : ~/workspace/...
0
votes
1answer
38 views

the pointer arrays

#include<stdio.h> #include<cs50.h> void test(char* msg) { puts(msg+6); } int main(void) { char* msg ="HelloWorld"; test(msg); return 0; } Here since char pointer points ...
0
votes
1answer
236 views

understanding pointers

#include <stdio.h> #include <cs50.h> void eatcandy(char a[]) { printf("%i", sizeof(a)); // **LINE 1:** } int main(void) { char chocolate[] = "tasty"; printf("%i", ...
0
votes
1answer
54 views

Passing Array's Pointer location and working in Array's memory location

OK - I am working on a snippet of code to make a recursive function that sorts values. I have kept banging on the code trying to make it work as I want it too. The code now runs and works as ...
0
votes
1answer
569 views

What does a command line argument stored in char* argv[] yields when assigning to another char*???

#inlcude <stdio.h> #inlcude <stdlib.h> int main (int argc, char* argv[]) { if (argc != 3) { return 1; } char* inf = argv[1]; char* outf = argv[2]; ...
0
votes
1answer
23 views

I have written this swap code but it is not compiling, Where's the bug

while compiling error says insert ')'at void swap(&a,&b); I can't understand this error here is the code #include <stdio.h> #include <cs50.h> void swap (int* x,int* y); int main (...
0
votes
2answers
42 views

Pointer variable

Say,the address of a variable 'a' is 64488 and aptr is a pointer variable such that int*aptr; aptr=&a; So,64488 is stored in aptr pointer variable.What I don't understand is how can aptr store 64488 ...
0
votes
1answer
238 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'...
0
votes
1answer
1k views

What happens when you assign a character string to a char* instead of writing element by element?

I have a question about strings that hopefully someone can help with. I realise that doing something like: char* word = malloc(4); word = "THE"; is not really correct (as word is really a pointer to ...
1
vote
1answer
36 views

Why does this snippet of code work?

I used address of operator on top of derefrence operator. Can you please explain what is happening behind the scenes. Here is my code: #include <stdio.h> int main(void) { int arr[10]; ...
0
votes
2answers
22 views

I made this copy program as in the shorts by david but it is giving two error described below

Here is the code with error message in the comments #include <stdio.h> #include <string.h> #include <cs50.h> #include <ctype.h> int main (void) { char* s=GetString(); ...
1
vote
0answers
256 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 ...
0
votes
1answer
73 views

Pset5: check() failed and questions about the usage of pointer

Something is wrong with my check(). It over-calculates the number of misspelled words. It seems that my code misses some conditions. Here is my code: #include <stdbool.h> #include <stdlib.h&...
0
votes
1answer
42 views

Cannot access beginning of the pointer

I have a problem with accessing first 4 integers of the 512 B pointer. Should I go with the struct? What would be approach to reference first 4 integers? Here is the line I am concerned of: // check ...
1
vote
1answer
99 views

PSET5 Question about pointers

I had a question for dictionary.c. First, I'm still confused at why load and check imput is const char*. I understand that const char* means that the value that char* points to will never change and ...
0
votes
1answer
53 views

A question about the fread function

Does the pointer move one position further after the fread function has read a pixel (for example)? I will try to be more articulate with this example: fread(&triple, sizeof(RGBTRIPLE), 1, ...
0
votes
2answers
130 views

What does free all pointers in children mean? (Unload function in Pset 5)

In the walkthrough video, it is told that we should free all pointers in children (trie). Does that mean that all pointers should be set to null? My program passes CS50 and valgrind doesn't indicate ...
0
votes
1answer
36 views

Pointers & Integer Arithmetic Question

trying to do a simple exercise on pointers because my recover isn't working (and I think it has to do with pointers). Wanted to write a program that reverses digits using pointers. Unfortunately I ...
0
votes
1answer
128 views

Pointers and End of File in Recover.c

recover.c seems to be working just fine. But then I realized I didn't employ a condition which tests the end of file. Why does it still work then? Should I modify my while condition? In addition to ...
0
votes
1answer
147 views

PSET 4 Resize: Pointers, arrays and file IO

Stuck on PSET4 resize: the file I'm writing is going into overflow and I'm not sure why. I've designed it using nested for loops as you'll see. It compiles and runs, but then it says the file is too ...
0
votes
1answer
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 ...
0
votes
1answer
110 views

pset6 parse: char* pointers are right in parse but return wrong value

I am having trouble with this pset and I am using gdb to step through the function. Should I worry about the following observations or should I ignore them and assume my problems are from something ...
0
votes
1answer
257 views

Segmentation fault in pset 5

I'm currently doing the load part of pset 5 and I ran into a problem I was not yet able to solve. This is my code: bool load(const char* dictionary) { FILE* dic = fopen(dictionary, "r"); typedef ...