Questions tagged [function-definition]
The function-definition tag has no usage guidance.
731
questions
1
vote
3
answers
90
views
Why my insertion sort can only sort 90% of the data?
I have to read a csv file and then sort its data basen on the dates in ascending order. The plot twist is that the 90% of the data is sorted correctly but the other 10% is not. The dates in the csv ...
2
votes
2
answers
28
views
Does this count as an Insertion-Sort? And why does a random number show at the end?
I've been asked to create an insertion sort for an array. My program ended differently from the teacher's, but it sorts the array. However, I'm curious if it truly counts as a proper insertion sort. ...
-2
votes
2
answers
59
views
Void function usage issue, I'm new to C [closed]
the task is to print ascending order numbers using only void function. Any insight on what's wrong with the code? Explanation too would be appreciated
#include<stdio.h>
void listNumbersAsc(int ...
0
votes
0
answers
12
views
How Do I Combine rich.Console().print(Markdown('- txt')) (Markdown Text) and ansimarkup's ansiprint() Function Together?
How do I combine rich.Console().print(Markdown('- txt')) (Markdown Text) and ansimarkup's ansiprint() function together?
I want to make a function that prints text that
can contain colors, simple ...
0
votes
1
answer
38
views
Can an Int * function return an int address? [duplicate]
So an int* function must retur a pointer to an int, but if a pointer to an int is assigned an int address, could an int* function return an int address? If not, why is it wrong? Thanks
int * function()...
0
votes
2
answers
36
views
Recursion to find length of a string in C
I am trying to find the length of a string by recursion using the following code:
#include <stdio.h>
int string_length(char *s, int x);
int main(void)
{
int length = 0, x;
char string[] ...
0
votes
2
answers
35
views
Deduce Function Arguments From A Function Type Declare, For Templated Struct Method?
I was wondering if it was possible to deduce the return type, and parameters from a function type define.
I was hoping to do something similar:
template<class T>
struct _function_wrapper_t
{
...
0
votes
5
answers
59
views
Stacks and Recursion in C
#include <stdio.h>
void fun(int a) {
if (a > 0) {
fun(a / 10);
printf("%d", a % 10);
fun(a / 10);
}
}
int main() {
fun(12345);
return 0;
}
...
1
vote
1
answer
76
views
how can I use less variables in my program?
I had to make a program that have an array of numbers, and then I need to make a function that get the arr[0] and the length of the array, and then it will print all the numbers without the duplicate ...
1
vote
3
answers
50
views
Last node is not printed in Linked List
I was trying to learn the Linked list and perform insertion operations from beginning of the list. while printing the nodes, the first node is not printed. Here is the core functions which I have ...
0
votes
1
answer
60
views
Function to rotate an array by one [duplicate]
I'm writing a function that takes as argument an array of integers and returns an array that is left shifted by one -- so { 6, 2, 5, 3 } returns { 2, 5, 3, 6 }.
Here's what I tried, but have issues ...
1
vote
4
answers
77
views
Need advice (hint) or help create 2 string function
The function receives two strings str1 and str2 and returns an integer. The function will insert the str2 string at the beginning of the str1 string. When the str1 string size will not change. If the ...
0
votes
0
answers
22
views
Defining a function in R with sum and product sequence
I'm having troubles in writing my cross-validated likelihood method. I have some data (vector of length n=272) and I need to define my likelihood function of variable h as: function definition . I ...
1
vote
1
answer
39
views
Reverse linked list in a function, that also has to work with a linked list
I had to create a function, that deletes nodes that have a greater element to the right. I achieved this by creating 2 functions:
1st function reverses a list
2nd function that deletes nodes, that ...
-1
votes
1
answer
70
views
how do i use an array of pointers in c?
Basically i have an array of strings and i need to check if they are arranged in lexographic order (case insensitive of upper or lower case, meaning it doesn't matter which one it is). For that I took ...
-3
votes
3
answers
57
views
How do i double only even numbers with an array [closed]
I have the task to use a function to double all even numbers in an array. It should look like this at the end:
Array before:
38 7 9 18 4 5 2 83 44 91
Array after:
76 7 9 36 8 5 4 83 88 91
all i have ...
-2
votes
5
answers
73
views
I cannot count more than one character
I'm trying to build a function that counts how many sentences there are in a text depending on the ?, !, and . to decide the end of the sentence.
For some reason no matter how many of them there are ...
0
votes
0
answers
5
views
Spyder: Definition lookup (Ctrl+G) all of a sudden not working
Getting pretty tired of all these random bugs in this IDE. This shortcut worked fine before, and now it's not. Any ideas? I made sure I didn't map the shortcut to anything else. It just stopped ...
0
votes
1
answer
49
views
Does Segmentation fault occurs due to accessing of large amount of memory
Insertion of large amount of random strings in Red black tree is giving segmentation fault in Ubuntu but the code work fine for insertion of few string(less than 50) . The code though works when it is ...
0
votes
3
answers
61
views
Segmentation fault on binary tree
I'm working on a program that searches through a program and outputs the number of times it comes across a number greater than or equal to the value specified in the parameter of the function. I have ...
4
votes
1
answer
35
views
SIGSEGV on access to pointer to left node of binary tree, even though the pointer is initialized
I am trying to create a function which returns the mirrored copy of a binary tree.
By "mirrored" I mean a tree with each left node as its right node and vice versa.
The one on the left gets ...
1
vote
2
answers
81
views
Why my returned value of strchr is ignored?
I have to make a function, that will code my sentence like this: I want to code all words with an o, so for example I love ice cream becomes I **** ice cream.
But my function ignores the result of ...
0
votes
3
answers
62
views
Duplication float values when using structs in a function
I have this program to calculate the midpoint given two points. It takes in the coordinates of two points and return the coordinates of their midpoint.
Somewhere along the way, my program started to ...
-1
votes
1
answer
37
views
I am trying to get my double linked list to display numbers 0 -> 10;
This is the struct definition.
typedef struct doubleLinkedList
{
struct doubleLinkedList *prevPtr;
int data;
struct doubleLinkedList *nextPtr;
} dNode;
typedef dNode *dNodePtr;
These are the ...
0
votes
3
answers
49
views
C function to sort part of an array not producing any output
I have an assignment to modify the selection sort to sort all of the values on the odd positions of an array in ascending order and to sort all of the values on the even positions in descending order. ...
-1
votes
1
answer
49
views
Why is the output junk value [closed]
In the below code, When I did the same logic without using functions it gave correct answer.
But with using functions its giving some junk value. The question was to print the sum of diagonal matrix ...
0
votes
2
answers
57
views
Control may reach end of non-void fct in recursive function [duplicate]
I know why and whats happening for this error. Mainly bc the return in inside the if. However Id like to fix the flow so its error/warning free.
Ive added inconsequential returns at the end as well as ...
0
votes
4
answers
56
views
Printing the largest element of an array
So this title is pretty garbage, I just really don't know how else to explain it. You'll get it when you see the code though, which is this:
#include <stdio.h>
void products(float values[], int ...
1
vote
1
answer
20
views
Numbers aren't showing up right
Hello there!
I'm kind of confused , I literally tried every possible sollution i could think of.
Yet the program isn't functioning right ! The purpose of this program is to seperate the odd numbers ...
-1
votes
2
answers
44
views
Finding the Minimum of Array while passing by reference
I am trying to write a void Function using pass by reference , that finds the minimum of an Array while only giving a pointer of an Array and the length of the Array as a Parameter into the Function.
...
-2
votes
1
answer
54
views
recursive function in c for the furmula: a(n)=a(n-1)+a(n-2)
I am trying to write a recursive function for the formula:
a(n)=a(n-1)+a(n-2)
I've tried to simply write it out:
unsigned int ladder(unsigned int n)
{
unsigned int ret=0;
if (n < 1)
...
0
votes
2
answers
53
views
empty pointers as an argument in C - problem with asterisks
The task is to fill an array with numbers by user input and then use our stats() function to calculate average etc. of each row of this array. The header of stats() function looks as follows:
int ...
1
vote
2
answers
69
views
Reversing an array by recursively splitting the array in C++
string recursion(int arr[], int arrSize) {
if(arrSize == 1){
return to_string(arr[0]);
}
string letterLeft, letterRight, letterFull;
//logic1: Normal Recursion
//letterFull = to_string(a[n-1]) + ...
1
vote
2
answers
96
views
Capitalize first letter of a word in a string in C
I have to capitalize the first letter of every word (words are separated by a space) into a given array of char. I wrote the code but I can't figure out why it's not working nor displaying anything in ...
2
votes
2
answers
48
views
My function that reverses a string gives me "stack smashing detected"
I am trying to write a function that reverses a given string but it gives me "stack smashing detected".
Here is my code:
void reverse(char *str2) {
int i, j;
char temp;
for (i = ...
1
vote
3
answers
56
views
Swap two ListNode* in C++
Please help, I am totally lost here. This is leetcode problem no. 24, swap nodes in pairs.
I am getting this error in screeshot.
/**
* Definition for singly-linked list.
* struct ListNode {
* ...
-2
votes
1
answer
33
views
linkedlist is not print out it's members
The code is in c++, I have tried to make wagons which using linked lists and each wagon has a type (like first class and second class), the code is not printing out the wagon details, I tried changing ...
0
votes
1
answer
46
views
Why is my code not dividing inside of the function?
I want to create a hailstone sequence using recursive function. But the even number is not getting divided, I want to know where and what did I do wrong?
#include <stdio.h>
int sequence(int n);
...
1
vote
1
answer
30
views
How to remove even occurences of a substring in a string
i am trying to remove even occurences of a substsring, for example if i have A11B11C11 and i want to remove 11, it will remove the ones on position 0 and 2, so it should look like AB11C.
This is the ...
-1
votes
2
answers
60
views
date structure and linked list printing problem
I am trying to creat a linked list in c language,
the code compiles with no error but when I run it , it won't run.
the data structure is a task which contains the label it's number, duration , number ...
0
votes
2
answers
73
views
How to parse a line into different variables in C?
I have a simple file, with integers and characters to be read. I read line by line and stored them in a char array and then split from the whitespace using strtok() and converted to int variables ...
0
votes
2
answers
42
views
Trying to delete node from a particular position . But I can only delete when in only input position 1 in the terminal
after running the code ,the program ask the position from where you want to delete a node . I ran the code but it only work when I input postion 1 .For other position like 2,3,4 it does not work .
...
1
vote
2
answers
42
views
my copy array function didn't work. i didn't understand why
This code has to copy one array to another via void copy function. But I don't understand why it doesn't work.
#include <stdio.h>
void copy(int func_array_1[], int func_array_2[], int size) {
...
-3
votes
1
answer
128
views
malloc(): memory corruption (fast)
I just started to learn data structure and getting an error when executing
malloc(): memory corruption (fast)
what can be the issue and how to resolve it?
I have called the following method in the ...
1
vote
1
answer
33
views
error: expected unqualified-id before ‘friend’
In my .cpp file I got
Student:: friend istream& operator>>(istream &input,Student &a){
input>>a.AM>>a.name>>a.semester>>;
return input;
}
...
0
votes
1
answer
47
views
Implementation of strtok()
I can't find an error in the implementation of strtok().
After executing the program, I get:
test1
test2
Instead of:
test1
test2
test3
test4
test5
test6
This is my program:
#include <stdio.h&...
0
votes
1
answer
44
views
find elements of an array in another array, why do I have this error?
I was trying to visualize the algorithm of this exercise, but I'm having a lot of problems.
the exercise asks to implement this function:
extern const void *memmem(const void *haystack, size_t hsize, ...
-3
votes
1
answer
69
views
Is it right to implement queue with single linked list?
My Code ↓
Some macros defined by
#include <stdio.h>
#include <malloc.h>
#define ElementType int
#define ERROR 0
// 队列用单链表实现
struct Node {
ElementType Data;
struct Node *Next;
}...
0
votes
2
answers
58
views
Why this function is not able to reverse the Linked List?
I want to reverse a linked list but when i compile this code it terminates unexpectedly.
#include <bits/stdc++.h>
using namespace std;
class node{
public:
int data;
node* next;
...
-2
votes
1
answer
59
views
Make own strrchr() function but case-insensitiv
my exercise is to create my own strrchr() function in c.
My solution is a loop. I'am counting the array length. I will input this number into the for loop. For example: With the input Hello. I will go ...