997 questions
0
votes
1
answer
113
views
Missing round_to() function in PPP_support.h
I'm currently working through Bjarne Stroustrup's Programming: Principles and Practice Using C++ (3rd Edition).
The book mentions a function named round_to() is provided in PPP_support.h
When, on the ...
3
votes
3
answers
173
views
remove a character by using conditional statement
recently just practiced the problem 67 in Leetcode This problem is like you would be given two binary string, and you have to calculate the sum of these two binary string and return the result.For ...
-5
votes
3
answers
124
views
How to fix printing declared function [duplicate]
I'm still new at functions and I tend to print the function which I don't know how to print the declared function. It prints "1" and not "John".
#include <iostream>
void ...
3
votes
4
answers
190
views
Change pointer adress inside function in C
I'm trying to make a program that deletes extra white spaces from a string. It should keep one space but delete any extra.
I wrote this code, which works up until the point I have to change the passed ...
1
vote
2
answers
66
views
Line extraction in a char
Hi i'm trying to write a recursive function to extract each line of a string. I don't know why it doesn't work i spent 2 hours trying to find the issue.
#include <string.h>
#include <stdlib.h&...
4
votes
6
answers
276
views
Function returning 101 and -101 instead of 1 and -1
So my professor gave us the assignment to code a function that works exactly like strcmp() but without using any library functions. I came up with the following code but instead of returning 1 or -1 ...
0
votes
5
answers
107
views
a heap-use-after-free wrong in the question--Design MyLinkList (LeetCode No.707)
Below is my C code for LeetCode no. 707 "Design Linked List":
typedef struct MyLinkedList{
int val;
struct MyLinkedList *next;
} MyLinkedList, *LinkList;
MyLinkedList* ...
0
votes
2
answers
98
views
Is it legal to have a function prototype slightly different from its definition?
//my_struct.h
typedef struct my_struct_t *my_handle;
void f1(my_handle handle);
void f2(my_handle handle);
//my_struct.c
#include "my_struct.h"
typedef struct
{
int a;
int b;
} ...
0
votes
2
answers
95
views
Avoid names of variables ending into function definitions in R
I would like to use values within variables for defining functions in R. However, after declaring the function I can still see the variable names instead of their values inside the function definition....
4
votes
2
answers
147
views
Function definition with prototype vs without prototype
There are (source):
void f(); // declaration (1)
void f(void); // declaration with prototype (2)
void f() { ... } // definition (3)
void f(void) { ... } // definition with ...
3
votes
0
answers
65
views
For function definition, what is the difference between using partial application, a lamba expression or put the arguments next to the name? [duplicate]
What are the differences between the three syntaxes
funName l = map fun l
funName = \ l -> map fun l
funName = map fun
In general it does the same thing however in some cases it differs.
The ...
2
votes
3
answers
179
views
Deleting selected element in a doubly linked list [duplicate]
I have written a code on deleting a node by comparing its data from the data given. If equal, it deletes the node. My problem is that my code will delete every node in the list except the last node, I ...
-3
votes
3
answers
155
views
How does does compiler know the definition of pre defined function even before linker haven't linked object file and library file?
We know that definition of pre defined functions are in library files, and it is the job of linker to link that library code(which is already compiled) to our object file (which has been created after ...
2
votes
1
answer
72
views
Why does the following base case for recursion in C not work?
I am practicing recursion function in C. The question is to create a recursive function to print a sum of all of the elements (int) in an array without changing the main function.
I know how to write ...
0
votes
1
answer
58
views
C++ Define member functions for all template specialized classes
I have a templated class foo<T> which is specialized in many different ways.
Some of which have a lot of common code that relies on specialized functions.
For example, consider the following:
#...
1
vote
2
answers
246
views
Returning the remaining string in strtok function?
I am writing my own strtok function. How do I make it so that it will return the remaining string as an output parameter?
Here is what I made so far.
char *mystringtokenize(char **string, char ...
0
votes
2
answers
210
views
Runtime error : Heap Buffer overflow in Leet code
I am having a problem with this code on Leetcode. In there , I am solving a problem to remove duplicates in an array but I am getting heap buffer overflow error -
Here's the code -
int ...
2
votes
1
answer
98
views
How can I implement a linear time implementation of a function that counts the number of occurrences of a non-consecutive subsequence?
My Programming I class assigned an exercise in which we have to implement a function that counts the number of occurrences of a non-consecutive subsequence in a string. This is what we're asked to do:
...
1
vote
3
answers
91
views
C: how to convert this code for an use with array?
Consider I'm still a newbie with C, so I made a lot of confusion.
This code works fine
int error(int a, int b, int c)
{
if (( a < 0 ) || (a > 255)) {
printf("Number is over 255 or ...
0
votes
3
answers
62
views
error in comparing elements of a 2d array using if-else statements
i tried to make a game using 2d character arrays. but the if else statements are not working and the loop is not breaking. Also when i assign a character to the last element of my row , the next row's ...
1
vote
2
answers
303
views
Fibonacci for letters
I was programming a code for a case provided by my university. It was about making a Fibonacci function, but for letters. For example, if f(0) -> a, f(1) -> b, then f(2) -> ba, and so on. I ...
0
votes
2
answers
1k
views
Cannot go to definition , in my vscode using robotframework
I am trying to use robotframework with vscode and installed robotframework language server , i am not able to jump to function definition .
expected response :- should jump to function definition when ...
1
vote
1
answer
88
views
Trouble with getting a function to calculate and loop correctly in C
I am needing to make a program to take user input of iterations to the formula : PI=4(1/1 -(1/3)+(1/5) ... repeating a number of times. MY problems so far is that it is not taking my input accurately.
...
0
votes
2
answers
191
views
Why do I get a segmentation fault? The code works fine in CLion and VSC
I am currently using exercism, to improve my programming skills. The code works fine in my IDE, but causes an error message on the website. What did I do wrong and how would you improve my code? Thx ...
2
votes
0
answers
65
views
issue with enable_if a template member function of template class, on a non-type template parameter, when defining it out of line
This issue occurs when trying to split the template into declaration and definition for ease of reading.
Consider this MWE
#include <type_traits>
template <typename T1, typename T2, int N = ...
1
vote
3
answers
81
views
I'm trying to call a function inside of a token loop in C. I keep segfaulting?
#include <stdio.h>
#include <string.h>
void pigLatinConsonant(char input[]) {
char end[] = "ay";
int length = strlen(input);
int first_vowel = -1;
for (int i ...
-6
votes
1
answer
759
views
Trying to build my own strstr() function in c?
I'm trying to build my strstr() function, it's look all fine
but when I execute the code it return nothing ;
This is my function :
#include <stdio.h>
char* ft_strstr(char *str, char *to_find) {
...
1
vote
1
answer
113
views
bubble sort in an structure in C
I've coded a program based on an array of structure and all parts of it are ok but one of my functions that is sort_student function has a bug. In this code at first the user will enter some students ...
0
votes
3
answers
103
views
Is there a way to avoid isEmpty() function for a stack?
The following program use an interger stack. Which value the function int pop() can return when the stack is empty, if I want to avoid using isEmpty() before calling the pop() ?
#include <stdio.h&...
-5
votes
1
answer
77
views
What is the formal definition of Θ(f(n)) without expressing Θ(f(n)) in terms of O(f(n)) or Ω(f(n))?
Θ or Θ(f(n)) is often defined in terms of O(f(n)) or Ω(f(n)). Other answers on this site define Θ(f(n)) in this way. What is the definition of Θ(f(n)) without using O or Ω?
Of course, since it is true ...
-1
votes
2
answers
326
views
Unsure why "function definition is not allowed here"
So this code is obviously incomplete and messed up but when I try to format my code I get an error here which I wasn't expecting (on the bracket after int getNumberFromSingleLine(char * singleLine)
...
0
votes
2
answers
214
views
CodeBlocks Compiler Giving "Undefined Reference" Error Over Usage of a Function Declared in My Header File
I'm getting the following error when trying to build and run my C++ Project:
||=== Build: Debug in CS II (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function 'main':|
|30|undefined ...
3
votes
3
answers
126
views
Why is the new string not being printed after adding char characters?
I'm stating to write some leetspeak code in C, however, I keep getting error like:
error: incompatible integer to pointer conversion returning 'char' from a function with result type 'string' (aka '...
-2
votes
2
answers
113
views
Read elements from keyboard until a negative value! Insert those elements into an array such that the array is always sorted
Read elements from keyboard until a negative value! Insert those elements into an array such that the array is always sorted.
I added the code and its outcome. I have a zero on the first position ...
1
vote
0
answers
26
views
Python: How to define functions in loops using outer-scope variables? [duplicate]
I want to define a function inside a loop using and changing variables which have been defined within the same loop iteration.
I would expect that nonlocal is just what i need here, but if i implement ...
2
votes
3
answers
485
views
move node from one linked list to another in certain conditions
I have a question that I am stuck with for a couple of days, and I need some help.
I have a function called splitList. The function needs to remove nodes from the original list and move them to a new ...
2
votes
2
answers
181
views
inline keyword causes linker error in Clion
I have a strange error concerning the inline keyword, this is just a sample code I wrote:
#include <stdio.h>
#include <stdint.h>
uint8_t inline LIB_MATH_BTT_u8GetMSBSetBitPos(uint32_t ...
1
vote
1
answer
1k
views
Typescript Return the enum values in parameter using a generic enum type method
I need to return a list with all values of an Enum (specified as parameter or generic). If the user has a specific role I need only some of the Enum values given as parameter.
I considered to write ...
0
votes
3
answers
697
views
Use function from other C file by a function pointer
First of all, I'm not sure if the title describes well the problem, feel free to change or suggest a more fitting heading.
I have the following problem:
I need to pass a function pointer to some ...
0
votes
1
answer
69
views
Trying to call a function in an "if... else..." statement, and its saying that the function below isn't defined
y = 0
x = 10
print("TRUE" if y>x else theloop())
def theloop():
while y < 11:
print(f"Number is {y}!")
y = y + 1
I want y to keep on getting bigger by 1 until it ...
2
votes
1
answer
166
views
Leetcode medium problem (Singly Linked lists)
1561/1563 test cases passed
problem discription:
You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes ...
0
votes
1
answer
123
views
Count Frequency of a Substring in a String
Given a string T and a pattern P which is also a string. Find the number of occurrences of P in T.
Input
Line 1: contains string P (length is less than or equals to 10^5)
Line 2: contains the string T ...
1
vote
1
answer
62
views
problem while taking the intersection of a list with another one
this function intersects the first list with the second, and it has to return a new list,
I've used elemtype.h and list.h, (of course with elemtype.c and list.c)
this is elemtype.c:
#define ...
0
votes
2
answers
93
views
Program hangs after modifying 2D array in a function in C [duplicate]
The program is a Tic-Tac-Toe game, and it hangs after taking the X and Y values from the user.
This is the main file:
#include <stdio.h>
#include <string.h>
#include "input.cpp"
...
-3
votes
3
answers
149
views
I have a program that capitalizes all words of a string. The program is working but I want to understand what the code is doing
#include <stdio.h>
char *cap_string(char *str);
int main(void) {
char str[] = "Expect the best. Prepare for the worst. Capitalize on what comes.\nhello world! hello-world 0123456hello ...
2
votes
1
answer
943
views
What are the correct types for memset function?
On trying to recreate "memset" function I have error if I try to dereference a void pointer, or have a different type for the second argument than the first. To make the function work I had ...
1
vote
2
answers
543
views
Dealing with a pointer to a bitset in C++
I have a bunch of bitsets<32> as global variables in my program and I want to update them after passing a pointer to one of them to a function.
Here is an example:
#include<bits/stdc++.h>
...
0
votes
1
answer
64
views
Operation on string inside function
Why does putting reverse() inside main() print 12345 while putting reverse() as the last statement of itoa() definition produces 54321?
#include <stdio.h>
#include <string.h>
void itoa(...
0
votes
2
answers
44
views
Can segmentation faults happen due to scanf statements
Written a program to find the multiplication of two polynomials using linked list. Checked for all the possible segementation faults finding no errors (checked the multiplication function).
#include&...
-1
votes
1
answer
82
views
How Can I Know If This Program Works As i Intended( Dynamic stack )
enter code herei was watching a video in data structures in C , and when i understand the abstract view of the concept i go try implementing it without watching the implementation in the video , and ...