Questions tagged [pointers]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
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
87 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
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
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
61 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
88 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
641 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
66 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
75 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 ...
0
votes
1answer
401 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
53 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 ...
7
votes
2answers
740 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
144 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
67 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 ...
-1
votes
1answer
427 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 ...
21
votes
2answers
58k 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
2answers
444 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 ...
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 ...
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
56 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 ...
0
votes
1answer
142 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} }; ...
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.
1
vote
1answer
229 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
309 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
160 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
1answer
695 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
84 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
2answers
120 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 ...
2
votes
2answers
350 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) ...
1
vote
1answer
983 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