Tagged Questions
In computer science, a pointer is a programming language data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memory using its address.
10
votes
4answers
819 views
Pointer version of strcat
Write a pointer version of the function strcat that we showed in Chapter 2: strcat(s, t) copies the string t to the end of ...
10
votes
2answers
141 views
strend, function that checks the occurence of a pattern at the end of a string
Write a function strend(s, t) which returns 1 if the string t occurs at the end of ...
10
votes
6answers
739 views
Simple word counter
I've decided to do this by writing a simple word counter. The app gets all the params and outputs all the unique words, each one with a counter:
"Hello world Hello" would return "Hello: 2", "world: ...
10
votes
1answer
87 views
9
votes
3answers
483 views
Tail implementation in C
Write the program tail, which prints the last n lines of its input. By default, n is 10, ...
9
votes
2answers
264 views
C struct or pointer to struct?
I am currently using this code (and more) to deal with 2D matrices. I am not very proficient in C, so I am not quite sure, if this is a good way of doing it.
I've seen other people in similar ...
7
votes
3answers
438 views
Implementation of stack using pointers
Please review my code and let me know how I can possibly improve it.
...
7
votes
2answers
360 views
7
votes
3answers
111 views
+50
Travelling Salesman in Qt
I am writing a recursive function based on the Travelling Salesman Problem.
Is this a correct way of doing things, or am I creating memory leaks?
Prerequisites are:
a two dimensional matrix ...
7
votes
1answer
62 views
Storing lines in an array
Rewrite readlines to store lines in an array supplied by main, rather than calling alloc() to maintain storage. How much ...
6
votes
4answers
161 views
Pass pointer data across multiple functions
I would like review on the following dynamic memory allocation process and suggestions on whether there are any memory leaks. Following code is not real code in use, but I'm trying to understand ...
6
votes
2answers
203 views
How best to keep track of an unknown number of objects?
I have a manager class that will manage an unknown number of objects. I'm currently storing the objects in a NSMutableArray object, and when I need to find one, I ...
5
votes
2answers
157 views
Linked list implementation in C
I'm learning C for mainly for fun and to get a better understanding of how things work under the hood (most of my experience lies with high-level languages). I've been following quite a few books and ...
5
votes
2answers
5k views
Learning to code a graph
This is my first attempt at putting the conceptual knowledge I've gained about graphs into code. When searching for examples they all seem overly complicated, and searching for a tutorial or ...
5
votes
2answers
191 views
Proposed solution to dangling pointers: a non-owning smart pointer
The lifetimes of various objects referring to each other are sometimes only known at runtime. For example, in a side scrolling shooter game, a HomingMissile ...
5
votes
1answer
56 views
4
votes
2answers
103 views
Optimising LinkedList class - Part 2
This is part 2. My problems are with too any pointers and with long body code in the following functions:
...
4
votes
1answer
78 views
Creating a list using a struct in C
I just got into structs and I decided to create a list using them:
...
4
votes
1answer
76 views
Writting day_of_month and month_day with pointers instead of array indexing
Rewrite the routines day_of_year and month_day with pointers instead of indexing.
The exercise is quite simple, this is the ...
4
votes
2answers
873 views
Heap implementation using pointer
I know heaps are commonly implemented by an array. But, I wanted to share my pointer implementation and have your feedback(s) :)
General idea:
I convert the index to its binary value and then trace ...
3
votes
2answers
93 views
Optimising a LinkedList data structure - Part 1
I have implemented a linked list. I feel I overdid it with pointers, used old standards and C++11, and I ended with too many lines of code. I will make my quotations into two parts: one for the ...
3
votes
2answers
126 views
3
votes
1answer
76 views
C dynamic array and pointers
I've written an implementation of a dynamic array in C, but I'm not sure if my implementation is correct... This is what I'm worried about: if I add an element, will it remain in the collection? This ...
3
votes
2answers
328 views
Am I using C++ pointers and references correctly?
I am a newbie to C++ programming and am currently reading this book called Jumping to C++ by Alex Allain. I have finished the pointers chapter and I am doing the exercises at the end of the chapter.
...
3
votes
1answer
81 views
Auto-recycling C++11 polymorphic smart pointers
I've recently read an interesting blog post by Philipp Zschoche:
it explains how it's possible to avoid unnecessary allocations/deallocations by keeping track of previously allocated memory in a ...
3
votes
1answer
43 views
getword that properly handles undersores, string constants, comments, or preprocessor control lines
Our version of getword does not properly handle underscores, string constants, comments, or preprocessor control lines. Write a better version.
This is the exercise 6-1 and can be foud on K&R ...
3
votes
1answer
127 views
list class for pointers with constant time item removal
This is a class I implemented that can be thought of as a highly specialized version of std::list<> for pointers. It provides the additional feature that the ...
3
votes
0answers
80 views
C++ class “overload” using variadic templates and wrapped function pointers
I'm using C++11 and I have the following problem (pseudo C++):
...
3
votes
0answers
96 views
Correct implementation of a one-wire temperature probe on a 328p arduino? [closed]
I'm not sure if I've got the correct implementation of pointers here, or if they're really even necessary. This is a condensed version of my code for a one-wire temperature probe on a 328p arduino ...
2
votes
2answers
96 views
Pointers for struct and `for`
I know something about pointers, but I'm trying to check my knowledge on a sample. Can somebody check if my code is good? I don't think that I should use pointers in these ...
2
votes
3answers
237 views
Review implementation of stack by using pointers in C
After I had my code for stack implementation by array reviewed I wrote stack implementation by using pointers. Here's my code. Any suggestions for improvement are welcome.
I'll be adding updated ...
2
votes
1answer
80 views
Bidirectional map based on memory manipulation
This is a bidirectional map implementation that stores the values as pairs on the heap, and uses pointer arithmetic for efficient lookup.
codepad link, may be easier to read
...
2
votes
1answer
77 views
Pointer version of itoa
Rewrite appropiate programs from earlier chapters and exercises with pointers instead of array indexing. Good posibilities include getline(Chapter 1 and 4), ...
2
votes
1answer
2k views
Modifying a string by passing a pointer to a void function
Please explain the relationship between pointers and arrays. In this tutorial, they change int c by changing *r in the ...
2
votes
1answer
398 views
C++ delegate implementation with member functions
I have been implementing a delegate class with C++11 that supports class member functions. I am interested in knowing if there are any potential problems with this implementation. My main concern is ...
1
vote
3answers
168 views
Checking success on functions in C/C++ [closed]
I am trying to understand best practices for C\C++ functions which retrieve data but must also give success/failure information.
Which is better, or is something different all together the correct ...
1
vote
1answer
41 views
Trimming exactly two white spaces from string at O(N) [closed]
This is the optimized code I have written for removing/trimming one white space from a given string. I'm required to remove exactly two spaces from the string at the same cost of \$O(N)\$ by ...
0
votes
1answer
93 views
Extract code that makes class shared_ptr construct-able only
I've tried using CRTP, but the forces the class to befriend CRTP Base.
...