Newest 'c' Questions - Stack Overflow

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
0answers
9 views

Unable to utilize gpio pin as digital input

I'm using stm8s103f2p 8 bit stm8 family microcontroller. I'm trying to use a GPIO pin (PD5) as digital input. I shorted PD5 to VCC but debugger is not showing any change, it is only showing "0". When ...
0
votes
0answers
25 views

What does this backslash do in this assembly code?

I am not sure what the difference is in these push lines. .macro PUSH_AND_CLEAR_REGS rdx=%rdx rax=%rax save_ret=0 pushq \rdx pushq \rax pushq %rll pushq %r12 .endm Do both push onto ...
1
vote
0answers
14 views

What compilation flags I need to use to get this `file` output?

I want to compile some code to run on an embedded Linux w/ MIPS arch. But I can't get my MIPS cross compiler (mips-linux-gnu-gcc) to compile my hello-world file correctly. I mean, it is compiling ...
0
votes
2answers
37 views

Null terminated C character arrays

1. Which of the following has a null terminator character added at the end? int main() { char arr[]="sample"; char arr2[6]="sample"; char arr3[7]="sample"; char* ...
-4
votes
0answers
18 views

set of angles to be matched after rotation allowing slight error

i have angles of 4 points in image (say a,b,c,d). Angle varies from 0 to 359 degrees in clockwise direction. Now I am given rotated version of above image. Angle of rotation is not known. Let us ...
0
votes
0answers
10 views

C AES-GCM Decryption of ESP packet not working

I'm trying to decrypt my ESP packet encrypted with AES128-GCM12. I used c openssl library for decryption. But decrypted result is wrong! I used two Linux 18.04 VM for simulating ESP packet with ...
0
votes
1answer
17 views

FreeRTOS priority 1 is special?

FreeRTOS priority 1 is special? In my system,i have 6 priority 0-5. I know the idle pro at 0. i assign a task at 1,others at 2-5.from the cpu time and IDEL pro info ,i could know the cpu have enough ...
-2
votes
0answers
31 views

how to change the arguments of main function before running it

In the following code, I want to change the arguments of main function without modifying main function. Recently, I read the code of AFL fuzzing tool, for the forkserver, I do not understand how to ...
-2
votes
0answers
16 views

Where should I store the password in my unix c program and how to protect it [on hold]

I'm creating a file server program in unix os where the server need to authenticate the user by using the username and password. I was thinking how should I protect the password and where should it ...
-1
votes
0answers
26 views

C Program reliant on fputs to reach conditional

I have the following snippet of a C program: char line[128]; int io; FILE *fp = fopen("/proc/diskstats", "r"); while(fgets(line, sizeof line, fp)) { fputs(line, stdout); if(...
0
votes
0answers
22 views

Reading from serial problems with Amazon FreeRTOS

I am attempting to read from the uart2 on an ESP32 DevKitC clone on a task thread. My code is as follows: uint8_t data[128]; data[0] = '\0'; //null terminate so we don't print garbage for( ; ; ) { ...
-2
votes
1answer
48 views

Getting information (types, values…etc) on members of C type struct

I would like to get some help on C-style struct. I do not have much understanding in C so I am not familiar with the basics. Right now, I have a struct (outerStruct) that has other structs as ...
-2
votes
0answers
26 views

What does “Undefined Symbol” mean? [duplicate]

I'm trying to add a file utility patch to the LambdaMOO server but the linker keeps giving me an "Undefined symbols" error for a variable in one of the object files. I don't think my problem is the ...
0
votes
0answers
44 views

Making an AST constructor for a compiler, can't figure out segfault

So I'm currently making a c-- compiler for a school project (due today) and I have a segfault that I can't figure out. There is a considerable amount of code don't want to overwhelm this question with ...
0
votes
1answer
64 views

C: Finding the bin index which a value belongs to

I have bins where the ranges grow exponentially. Bin 0 -> [0 <= x <= 10] (interval = 10) Bin 1 -> [11 <= x <= 30] (interval = 20) Bin 2 -> [31 <= x <= 70] (interval = 40) ...
0
votes
0answers
21 views

How to fix c 'cannot open file xxx' error by including corresponding files?

I'm running a shell script on a board. The shell command looks like: ./gmx mdrun -notunepme The error is: source code file /home/../gmxfio.c cannot open file: topol.tpr This gmxfio.c file is not ...
0
votes
2answers
55 views

Store doubles in an array in C

I really need help to store double values in a double array. I am trying using scanf_s and it works. But if I try to input more than 4 values, my program crashes and returns me the error code 3 I ...
0
votes
1answer
37 views

Why does the scanf cause my code to be running indefinitely?

When I try to run this code it just runs indefinitely. I have tried to use scanf_s but that did not change anything. #include <stdio.h> int main (void) { int height, length, width, volume,...
0
votes
0answers
33 views

Determine if we can put '+' and '-' between numbers so that the result is divisible by a number: where's my mistake?

We have howmanynums numbers. We must determine if there's a way to put '+' and '-' between them in a way that makes the result divisible by given number mod. (It is preferred to do it by means of ...
-1
votes
0answers
16 views

How to fix string concatenate with single variable in C

I am working on a project using Arduino. Users are sending SMS to the Arduino sim card and the content of the message will be extracted and store in my MSQL database using PHP. How can I get the ...
0
votes
0answers
40 views

Need to add bytes whose sum is > (int) 255 [on hold]

I have an array holding single bits and implemented a stack. Until now I have only been pushing bytes of size smaller than 255. I have an Iadd operation that requires to store the size of bigger ...
-1
votes
1answer
30 views

Is there an way to get any button pressed in ubuntu, even those not pressed inside my C/C++ application window?

I'm developing a small app that will show an alert whenever I haven't pressed any key or clicked any mouse button for a while, just for helping me focus. But, I can't find a way to get buttons pressed ...
0
votes
1answer
32 views

Initializing and using struct members inside another struct

I need to use a struct (struct1), that was previously declared, inside a new struct (struct2). Also I want to initialize it, and use some of the members of struct1 to initialize other members of ...
-3
votes
0answers
19 views

How can we transform the code below as a switch case? [duplicate]

I would like to know how can we transform the code below as a switch case statement: if ( a== 1 || a==2 || a==3) b=10; else { if(a == 4) b=20; else b=0; }
0
votes
1answer
22 views

How to get one correct value from a function which is parallelized by multi-threads

For faster calculation, trying to make my method parallelized by 4 threads. Where threads are making 4 separate calculation whether I was expecting concurrent operation and on single variable. #...
0
votes
0answers
43 views

How to interpret the following line in the c language? [duplicate]

I am working on linux and came across the following declaration:- static noinline void __sched __mutex_unlock_slowpath(atomic_t *lock_count); Since I am new to this I am not sure how to read and ...
0
votes
1answer
29 views

OpenMP parallel 'for' doesn't work properly

The following snippet is from one of the functions of my code: static int i; #pragma omp parallel for default(shared) private(i) schedule(static,1) for (i=0; i<ttm_ic_last; i++) { static int ...
2
votes
1answer
44 views

Vanilla C drop in replacement for intel intrinsics?

For each avx, sse4 etc intrinsic there is an open logical algorithm. I wonder if there is an official or unofficial drop in replacement of intrinsics with vanilla C code (for debugging, prototyping on ...
0
votes
1answer
17 views

How to change volume of Speaker using Alsa library?

I am controlling volume of Speaker using Alsa amixer library on Linux. The problem I have is that its not controlling volume in a proper scale between [0,100] percentage.This sample code I got from ...
0
votes
6answers
78 views

How to force C to interpet variables as signed or unsigned values?

I am working on a project where I often need to interpret certain variables as signed or unsigned values and do signed operations on them; however, in multiple cases subtle, seemingly insignificant ...
0
votes
0answers
21 views

Codeblocks C Debugging

I've got a new challenge to return the factorial of a number. Got ideas on how to do this, but the challenger has given some starting code - which is shown below. Now this isn't how I would have ...
0
votes
0answers
29 views

mktime and localtime causing Segmentation fault, how to properly initialize?

I have the following function that is repeatedly called within a larger program: double troublesome_function() { time_t time_ini = time(NULL); struct tm tm_ini = *localtime(&time_ini); (...) ...
0
votes
0answers
47 views

Output to both console and txt file

I think this is written in C, honestly don't know how to identify (if someone could give some tips it would be great). When the command rpt dumpvars 1234 is run in the console it returns the variables ...
1
vote
2answers
66 views

adding char as int gives unexpected result

I try to do some hex-bin/bin-hex conversion and test which function would be faster but I encountered strange error while adding 'a' as integer. #include <stdio.h> /* convert bin to hex char [...
-5
votes
0answers
34 views

No matter how you think, you can not think of a solution to the algorithm [on hold]

View an algorithm and create code in c language. To get to the pointand I wrote the code on the terms of the problem. I'm writing code well but it keeps clogging.Help me :( If you have any point ...
-1
votes
1answer
32 views

How do I count correctly processes created by fork?

I am having problems with C code about processes that are created with fork given by our professor to figure out the number of processes that it creates. pid1 = fork(); if (pid1 != 0) { pid2 = ...
-1
votes
0answers
15 views

Failed activation of DJI Matrice 100 Drone

I am trying to run a sample application for the Matrice 100 by using ROS on a raspberry Pi 2.I have the Pi connected to the drone via USB-TTL cable to the UART port on the drone. I have my laptop ...
0
votes
0answers
20 views

Search for Files and Create a Number of Copies

Very new to coding... bare with me. I am using Cygwin, and I am trying to write a function that takes in two arguments, a file name, and an integer. I would like the function to search through ...
0
votes
0answers
19 views

Symbol conflict in transitive dependencies of two dynamic libraries

I am using two third party dynamic libraries: liba.so and libb.so. They both call a function named common included in another dynamic library, but liba.so should use the one from libsuba.so while libb....
1
vote
2answers
32 views

How can I write a function to copy an array of items for some defined number of items to copy

Im trying to learn how to use pointers and want to write a function where I have two arrays of integers and want to copy an array of integers for a specific number(nbr) of integers to copy. int A[]= {...
-1
votes
1answer
57 views

How to call system call from kernel?

I'm trying to invoke the getrusage() system call from kernel space, but I don't know how. I read about getting the kernel export (Can we call system call in kernel space?), but I don't know what that ...
0
votes
1answer
43 views

Defining a pointer function inside a struct

So I was trying to accomplish to write a struct with pointer functions in it and this is what I wrote typedef struct Coordinates { float x; float y; } Coord; typedef struct Parallelograms { ...
1
vote
1answer
109 views

Taking a crack at project euler problem 3, is my solution correct?

Problem 3 of Project Euler reads as follows: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? I've made this solution, makes sense, ...
-6
votes
3answers
82 views

Why is this C code section flagged as bad? [on hold]

I am new to c. I come across this section of code in C, it's flagged as a bad code. Not sure why it's bad and any suggestions for improvement? The original code is from this link: https://pastebin....
-1
votes
1answer
34 views

Why am I getting extra char when printing an array [duplicate]

I am new to C and I'm getting confused about printing arrays. Consider this simple code: char myName [5] = "tamir"; printf("My name is %s" , myName); The output of this is "tamirH", with extra H at ...
1
vote
2answers
71 views

How to convert an int8_t array to int32_t array in C

I have an array and I want to convert it to an int32_t array. I tried the code below. int32_t const_data[11]; int8_t buffer[44]; int k = 0; while (k < 11) { for (int j = 0; j &...
1
vote
1answer
49 views

Print 3 boards with borders in C

So im trying to print 3 boards, each one is a 2d array, i managed to print the first one but im having trouble with the other 2. any help is appreciated. here is how it looks now: void ...
2
votes
4answers
81 views

C : If as I understand 0 and '\0' are the same, how does the compiler knows the size of an array when I write int my_array = {0};?

I am trying to create a function to copy an array into another using pointers. I'd like to add the following condition : if the array of destination is smaller, the loop must break. So basically it's ...
0
votes
0answers
36 views

ISO 8601 Get Week and Year Number without time.h mktime

I'm trying to calculate the week and year based off of a unix time date (input as UTC, so locale can be ignored). I cannot use this library because of memory constraints on my hardware and because one ...
0
votes
0answers
20 views

Importing DER encoded private key using GnuTLS library fails

I need to import a private key (.der format) to the gnutls_x509_privkey_t structure. For that, I first parsed the DER private key file into char[] using file operations. Then I have used ...