Questions tagged [pointers]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
413 views

Why does “if (input[i] == ” “)” throw an error of “incompatible integer to pointer conversion”?

This question took me long enough to figure out that I figured I would ask and answer in case some future student had the same problem. I actually had the same problem in Psets 1 and 2, but I took a ...
0
votes
1answer
27 views

pset5 Can't seem to get pointers right for `unload()`

This is my struct node defined in dictionary.h typedef struct node { bool is_word; struct node* children[27]; } node; struct node* root; This is the part of the code I'm having problems ...
0
votes
1answer
133 views

Want to make sure I understand struct, malloc, and pointers and how they relate to each other

Sort of related to PSET4 resize, but actually want to make sure I understand this in general. So at first I just declared a struct BITMAPINFOHEADER called "new_bi" and dealt with it while avoiding ...
0
votes
1answer
59 views

difference between string, pointer, array and int

while it hasn't been something which really stopped me from learning, there is something which has been keeping me awake for the last few days... What is the difference between: #define x 5 int i; ...
0
votes
1answer
25 views

Pointers in a function

Can someone please explain, why list-printing cycle with pointers works perfectly fine from main(), but refuses to work from separate function when called. #include <stdio.h> void listPrint (...
0
votes
1answer
64 views

Pset4 Recover fails check, looks right and file sizes are right

struggling with the last piece of the puzzle for Recover. I'm pretty sure It's related to a memory leak of sorts, but I fail to understand how to resolve it. Here is my code: http://pastebin.com/...
0
votes
1answer
58 views

Linked list doesn't print out the correct values (when using fopen)

When I run following program with a list of 5 words I keep getting an output of last last last last last opposed to last fourth third second first (ie the contents of the word list which I am ...
0
votes
1answer
38 views

Precedence Short: What does “&x” do?

After watching the precedence short I was left with that question.
0
votes
1answer
87 views

Pointers basic Concept with functions

http://cslibrary.stanford.edu/102/PointersAndMemory.pdf Reading this told us that when function gets called its locals gets called and when it exits its locals gets destroyed so that we can't use its ...
1
vote
2answers
544 views

Update a value in the function

I want to update variables relating to velocities in a different function to where it is declared. But am not fully understanding the syntax for it. I have the prototype as follows: void moveBall(...
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
65 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
1answer
74 views

Does IF condition increment file pointer?

Will: if(some_filepointer != NULL) { // do this } increment the file pointer? does the evaluation move the pointer to the next character in the file because the if condition read from the file?
0
votes
1answer
1k views

error: invalid operands to binary expression ('int *' and 'LONG' (aka 'int'))

I'm pretty sure I'm using pointers incorrectly but I don't fully understand why using them in this way is wrong. The compiler seems to throwing out an error on the line (near the bottom of the code) ...
0
votes
1answer
6k views

How to iterate through an array using pointers

I managed to "solve this issue", but I don't know why I get the problem I get. Right after the last line I also got a segmentation fault, which I failed to include in the above screenshot. My ...
6
votes
2answers
384 views

How can char* contain a collection of characters instead of a memory address?

I'm a little confused as to how C treats int* differently from char*. For example, in section, we see things like: int x = 5; int* ptr_x = &x; So, here, ptr_x points to the address in memory of ...
0
votes
1answer
399 views

Pset 3 error - Binary search

I'm having some difficulty implementing binary search. I wrote linear search with no problems but when I compile my code for binary search, I get an error. I decided to take the iterative approach ...
1
vote
1answer
43 views

Pointer and scope

I know that when I create a pointer and use malloc() to allocate some chunk of memory, that memory is located in the heap. Where is the pointer itself stored? Is it in the stack like any other ...
0
votes
1answer
558 views

Can I create and initialize arrays of other types the same way I can create and initialize char arrays?

I'm a little confused about arrays and pointers and what is correct. I know that you can use char* str = "foo"; which is a pointer to the first block of memory for the string foo. But let's say ...
0
votes
1answer
139 views

Speller Dictionary: Problem with Pointers

I am a bit confused by all the new things about pointers. We can access a the value of a pointer by dereferencing it. For example, if you have char* str, you access the information that str is ...
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
410 views

Bad pointer null assignment followed by malloc fail — WHY?

I'm stumped! In dictionary.c I have coded the load function (with more code that follows the bug, but not needed for this question.) One small block of code is producing a problem! Assigning NULL to ...
0
votes
3answers
34 views

Location of pointer as opposed to location pointed to?

I'm taking CS50 via edx. One of the videos dealing with pointers (can't find it now) runs a program called noswap (under GDB) that highlights how C uses copies of variables (in this case, int a and ...
0
votes
2answers
425 views

different between pointers and pointer to arrays?

difference between -- char a[SIZE]; //Char array of size (SIZE) char *a; //character pointer. Points towards a char (a). char *a[SIZE]; // Array of pointer characters. char *(a[SIZE]); // Pointer ...
0
votes
1answer
55 views

Whats the adress of this string?

int main(void) { char* str="world"; printf("%s\n",str); } I think that i have understand the int pointers but with the chars pointers is still fuzzy.. I can't understand the above ...
1
vote
2answers
2k views

Checking the base address of pointer string

#include <stdio.h> #include <string.h> int main(void) { char *a="World"; char *b; printf("a=%p\n",&a); // Base address of a b=a; // Base address of a ...
1
vote
1answer
196 views

How can I avoid segfaults when sorting my linked list?

I have been working hard with speller but I am stuck when it comes to inserting the nodes in alphabetical order. I am pretty sure I am doing something wrong, but I am not sure exactly where the ...
1
vote
1answer
2k views

Dynamic string length allocation in new_node->word; array type char [46] is not assignable

I am trying to make my node size dynamically change with the size of the word from the dictionary in the load(dictionary) function. I understand that the warning means I am trying to assign a pointer ...
0
votes
1answer
158 views

Am I creating an array of pointers or an array of structs?

I've read an answer to a similar question about node* new_node = malloc(sizeof(node)); and how it allocates memory for the pointer plus all the data contained within the struct as it was declared ...
1
vote
1answer
140 views

Why isn't a dereference operator used when doing File I/O in C

It might be a dumb question, but I've searched and couldn't find an answer. For example FILE *fp = fopen (argv\[1\], "w"); ... fputs (input, fp)[1]; The fp doesn't have a * in front of it. I ...
0
votes
2answers
114 views

Pointers and asterisks

I searched and found Luke's very detailed reply to a similar question, however, my question (and confusion) still remain. I don't understand why we can malloc a pointer to a struct, and this also ...
1
vote
1answer
813 views

Why Am I Having a Memory Leak?

Considering this simple program, // preprocessor directives #include <cs50.h> #include <stdio.h> #include <stdlib.h> // define a struct typedef struct structure { string str; }...

1 2
3