Questions tagged [c]

C is a general-purpose programming language used for system programming (OS and embedded), libraries, games and cross-platform. This tag should be used with general questions concerning the C language, as defined in the ISO 9899 standard (the latest version, 9899:2018, unless otherwise specified—also tag version-specific requests with c89, c99, C11, etc). C is distinct from C++ and it should not be combined with the C++ tag absent a rational reason.

0
votes
2answers
33 views

How to fix 'access past the end of a local variable' in c

I made a function that checks to see if 6 elements of an array are equal, and if they are it changes a value of a different array. It compiles, but when I run it I get a 'stack buffer overflow' and my ...
1
vote
2answers
31 views

variable sized object may not be initialized

I am getting the error variable sized object may not be initialized and I don't understand why. Could someone show me how to fix this line? int arr[size] = (int *)(augs->one); Here is my code: ...
-2
votes
0answers
12 views

How do I interface a gas sensor to the adc of nucleo STM32 l152re board?

I need the code for interfacing an a mq-7 CO gas sensor to the adc of STM32 Nucleol152re development kit
2
votes
2answers
38 views

How to pass structs to C function from x86-64 assembly on Mac (NASM)

From here: nanosleep((const struct timespec[]){{0, 500000000L}}, NULL); It passes a struct. I am not sure how to pass structs to the syscall or library functions via registers. Wondering if one can ...
-1
votes
0answers
20 views

pthread_join fwrite for loop only writing a single threads data to my file (C)

I have 4 threads, using C FILE* out = fopen(fileout, "wb"); for (int i = 0; i < NUM_OF_THREADS; i++) { unsigned char* temp; pthread_join(tid[i], (void**)&temp); fwrite(temp, ...
0
votes
3answers
29 views

How to fix code that extracts even numbered index values in an array of a sentence and combines it with odd numbered index values?

Basically, my code is supposed to encrypt a sentence(or word) by taking out all the even numbered index values(starting from 0) and the odd numbered index values and placing the even index values ...
0
votes
1answer
27 views

Reading comma separated numbers (coordinates) from a text file in C

I'm trying to read some numbers in C from a text file which contains 1000 lines of numbers such as: -340,495,-153,-910,835,-947 -175,41,-421,-714,574,-645 -547,712,-352,579,951,-786 419,-864,-...
1
vote
0answers
33 views

Program compiles, but receiving incorrect answer - Simpson's Rule integration in C

I'm trying to calculate the integral of sin(x) from 0 to PI in C using a Simpson's Rule function. My program compiles, but I receive the answer of 0.0000 no matter what I input. Can anyone advise? /*...
1
vote
2answers
39 views

Why this counting sort return input instead of sorted table?

I'm writing counting sort in C. N is the number of elements in table which is to be sorted, k is max value that any of this element can be. However, this code, leaves me with the same table as the ...
1
vote
1answer
34 views

Extracting a string between two similar (or different) strings in C as fast as possible

I made a program in C that can find two similar or different strings and extract the string between them. This type of program has so many uses, and generally when you use such a program, you have a ...
1
vote
1answer
27 views

Mac OpenGL window movement required to show something

I'm starting OpenGL with C, so I started up a CLion project and got started. For reference, I'm on a Mac 10.14. This is my CMakeLists.txt: cmake_minimum_required(VERSION 3.10) project(GLMC C) set(...
0
votes
0answers
48 views

How to call C function from x86-64 Assembly on Mac (stack alignment and/or Makefile build issues)

tl;dr I am getting a few different errors depending on how I try to call a C _print function from x86-64 assembly. I would like to get it printing by calling the C function, so I know I can call C ...
7
votes
4answers
271 views

How to hide some fields of struct in C?

I'm trying to implement a struct person and I need to hide some fields or make them constant. A trick for create private fields. Header: #pragma once #define NAME_MAX_LEN 20 typedef struct _person ...
0
votes
1answer
23 views

C code: system(“”) Returns -1 Errno=10 when logged into Oracle

After an EXEC SQL CONNECT user/pass; command, system("") returns a -1 with errno=10. We've migrated this program from Oracle 10g on HP-UX to Oracle 11g on Red Hat Linux. This was not happening on HP-...
0
votes
1answer
11 views

Universal USER in Directorys?

I want to write some text to a text file but I need a universal USER at the directory. E.g. C:/Users/USER/Desktop/test.txt #include<stdio.h> #include<stdlib.h> #include<time.h> #...
-2
votes
0answers
55 views

My code works at dev c++ but it doesn't works at hackerrank

It gives expected output at dev c++ but it gives wrong output at hackerrank. Why, I don't understand that. Can someone explain? How can i fix this? I use long long it. Maybe it causes a problem? ...
1
vote
2answers
38 views

C - Counting number of same elements in 2 arrays

Let's say we have 2 arrays: char arr1[1024]="ABDDDABAC"; char arr2[1024]="DDDABKDDJABAJJ"; and would like to determine the position at which arr2 has the maximum number of matching elements as arr1. ...
-1
votes
1answer
34 views

How to include JSON file/object inside C++ at build time

I have a JSON File with database environment configuration called env-config.json like this: { "LATEST":{ "DB_DATABASE":"databasename", "DB_HOST":"hosturl", "DB_PORT":"3306", "DB_USER":"root", "...
0
votes
0answers
43 views

Why does c implementation of BST not include a data and key?

I come from a java background so I'm a newbie when it comes to c. Please excuse me if my question is naive or something; my only goal is to learn. I was looking at different implementation of ...
0
votes
2answers
52 views

wrong conversion of two bytes array to short in c

I'm trying to convert 2 bytes array to an unsigned short. this is the code for the conversion : short bytesToShort(char* bytesArr) { short result =(short)((bytesArr[1] << 8)|bytesArr[0]); ...
0
votes
0answers
9 views

How to get mouse pointer position with respect to a GtkImage

I develop in C a GTK graphical user interface consisting in a main window embedding a GtkImage widget. I cannot retrieve the correct mouse pointer coordinates with respect to the GtkImage widget ...
0
votes
3answers
53 views

Multiply a digit array by int in C

I have a very large number (>100 digits long) so it can't be stored as an int or even an unsigned long long (aka uint64_t). The array looks like this: {5, 1, 2 ... 8, 6} The array must contain single ...
0
votes
2answers
29 views

Is my diagnosis of the cause of “Could not find platform independent libraries <prefix>” correct and how can I fix it?

I'm trying to embed python into a C application. For the moment, I am trying to get the following hello world style example working #include <..../anaconda3/include/python3.7m/Python.h> // I'...
1
vote
0answers
32 views

Issue with Inserting Token into Hashtable

I'm putting together a program to parse through large text files, count how many times each word appears and then use that data to perform other calculations and comparisons. At the moment, I'm ...
2
votes
1answer
52 views

Char Array and uintptr_t

I was reading What is uintptr_t data type but still I'm unable to understand uintptr_t here as what purpose it serve by first converting temporarily char array type to unsigned long int type and then ...
0
votes
2answers
31 views

Why does passing function parameters to a struct initialization return junk or seemingly not do anything?

I'm trying to make a function in c to create and return a new struct similar to a constructor in OOP. When checking the variables the string is junk while the numbers are all 0. Can structs not be ...
0
votes
1answer
29 views

C fscanf delimiter with a long

I'm trying to read from a .csv file in C and it works for my character arrays, but not for my long. char fname[24]; char lnem[48]; char email[36] long phone; fscanf(fp, "%[^,],%[^,],%[^,]%*s,%lf", ...
-3
votes
1answer
44 views

Algorithm complexity with iterations. Is it logarithmic or exponential?

If I have the following algorithm for (i = 1; i <= 4 * n; i = i * 4) { for (k = 1; k < 1000; k = 2 * k) { print(k); } print(i); } how can I calculate its complexity? I only ...
-6
votes
1answer
38 views

Execute callbacks in a thread c/c++ [on hold]

I am using a library that returns some data via callback API. Data size is small ex. 200 bytes. This callback is called very frequently. It is not recommended to do computation on data in callback ...
0
votes
2answers
77 views

Comparing two array values in C

I am writing a program for school project in C which compares the values of two arrays and gives specific results depending on what the input was from user. Basically my output values are two, ...
2
votes
1answer
92 views

Getting wrong multiplication result in C

I'm working in a C code for calculating pi with the precision of 80 decimals, using Archimedes method. This video may elucidate about the method. I'm basically calculating Pi by starting with a ...
-1
votes
1answer
26 views

passing argument makes pointer from integer without a cast / expected ‘double *’ but argument is of type ‘int’

I'm very new to C and I'm getting errors in my C program assignment. I'm generating a 4x4 Hilbert matrix and then finding it's determinant via Cramer's Rule. But I get the following errors on my code ...
1
vote
1answer
39 views

How to suppress “warning: cast to pointer from integer of different size”?

TL;DR: I need to do the following in my code (greatly simplified example): int ret = 42; void * marshaled_ret = (void *) ret; int unmarshaled_ret = (int) marshaled_ret; This results in the compiler ...
3
votes
4answers
57 views

C Unexpected Output [duplicate]

By executing this code: float f = 1.0; while (f != 0.0) { f = f - 0.1; printf("%.1f\n", f); } It is expected that it would run 10 times and stop, but what turns out is that it inevitably ...
0
votes
0answers
26 views

“Subscript requires Array or Pointer” Error

I am trying to find the sum of values in an array, but keep getting different type of errors. I am currently getting a "subscript requires array or pointer" type error. My code for user entering ...
0
votes
0answers
32 views

“__u8 b[16]” vs “unsigned char uuid_t[16]”

Is there any difference between the following constructs 1. #define UUID_SIZE 16 typedef struct { __u8 b[UUID_SIZE]; } uuid_t; 2. typedef unsigned char uuid_t[16]; To my untrained eye they ...
0
votes
2answers
62 views

How do I iterate through multiple arrays

How would I iterate through these 5 array in a function call? Right now I am just manually iterating through each to form a specific character
-8
votes
3answers
45 views

What type should be used to loop through an array? [duplicate]

Let's have this array: char arr[SIZE_MAX]; And I want to loop through it (and one past its last element): char *x; for (i = 0; i <= sizeof(arr); i++) x = &arr[i]; (Edited to add ...
0
votes
1answer
21 views

Passing a value to a child's process handler

Let's say i create via fork a child process from a father process and i pass an X value to child process using a pipe.At first the child is on pause and i start it using a SIGINT signal.What i want to ...
0
votes
1answer
37 views

free() function not freeing heap memory

I have 3 files proj2.c, duplicate.h, duplicate.c proj2.c: #include <stdio.h> #include "duplicate.h" #include<stdlib.h> int main(int argc, char **argv) { if (argc <= 1) { ...
-1
votes
1answer
47 views

error: expected ';', ',' or ')' before '.' token?

I'm writing a program in C with structs and pointers etc. However, when I run it, it gives this error: "error: expected ';', ',' or ')' before '.' token" at the following line char *strcpy(char *...
-3
votes
0answers
28 views

How many new processes are created in the following code and why? [duplicate]

void main(){ int a = 0; a += (fork() != 0) ? 2 : 3; if (a == 2) fork(); a++; if (a == 3) fork(); } I'm trying to figure out how many new processes are created in the following ...
0
votes
2answers
67 views

C program to calculate sine is giving an inaccurate results

I have to write this program only with #include<stdio.h>. I have to read the highest power of the series 'n' from the user. When x=45 and n=9, then the program gives me 0.7068251967. But ...
2
votes
4answers
69 views

Assign result of sizeof() to ssize_t

It happened to me that I needed to compare the result of sizeof(x) to a ssize_t. Of course GCC gave an error (lucky me (I used -Wall -Wextra -Werror)), and I decided to do a macro to have a signed ...
-1
votes
0answers
14 views

Use of shared memory in CUDA broke my convolutions

I have written the following CUDA code to perform edge detection on an image: #include <cuda.h> #include <math.h> #include "kernel.h" #define BLOCKSIZE 32.0 __global__ void ...
0
votes
0answers
26 views

Arduino GUI to Overwrite variables

I'm searching Any Arduino GUI to overwrite variables. For example I have value speed in my Arduino code. I want to display actual value (not necesarry) of this variable, overwrite it and send changes (...
0
votes
0answers
13 views

eclipse gdb conditional breakpoint stop after hitting another breakpoint

I'm using Eclipse CDT and I'm wondering if there's a way to emulate Eclipse's Java trigger points functionality with GDB. Right now the only way I see is to have a global variable and use that as a ...
-1
votes
1answer
48 views

undefined reference to gcvt

#include <stdlib.h> #include <stdio.h> int main(){ float x = 123.457; char buf[100]; gcvt(x, 6, buf); printf("buffer is: %s\n", buf); return 0; } I have an undefined ...
0
votes
3answers
78 views

C Reading a file of digits separated by commas

I am trying to read in a file that contains digits operated by commas and store them in an array without the commas present. For example: processes.txt contains 0,1,3 1,0,5 2,9,8 3,10,6 And an ...
0
votes
2answers
52 views

How to “clear” an array in c to make room for a smaller array?

I have an array in C, let's suppose it's **arr = malloc(100 * sizeof(char*)); through some function, I populate this array in such a way that it ends up being arr = {"first", "second", "third", "...

http://mssss.yulina-kosm.ru