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.

Filter by
Sorted by
Tagged with
-2votes
0answers
8views

How do I solve this linked-list problem. A solution would be very appreciated

I need to write C program to create a grouping tree using linked list implementation and traverse the tree in preorder. For each visit to the node, I need to print the student name and id to the ...
user avatar
0votes
0answers
4views

I have installed MinGW and codelite and everything works except showing "locals" when stoping at a breakpoint when debugging

I have installed recently on mi windows 10 the MinGW for using it on C development plus codelite. Everything works, I can compile and run programs, but I can't find the way to make the debugger show ...
user avatar
-1votes
1answer
22views

formatting the output in a C program from two functions on same line

The above is the current output. Below is the expected output How can I modify my program to get the output in the expected format? What could be the easiest way to do it? Currently, I am printing ...
user avatar
  • 11
0votes
2answers
14views

What are the various ways to disable and re-enable interrupts in STM32 microcontrollers in order to implement atomic access guards?

The standard technique to enforce atomic access to volatile variables shared with ISRs, via "atomic access guards" or "interrupt guards", is as follows: // 1. save interrupt state /...
user avatar
-1votes
1answer
22views

Writing my own itoa function from scratch with no stdlib

I am completely new to coding and have got this solution to another post working. I was wondering if there was a way to get it to work with negative integers as an input. I don't have access to the c ...
user avatar
-1votes
0answers
15views

My variable won't store my arithmetic response in c, stores in identical variable though

I am trying to compute a value that will be obtained from the ADC. For some reason, my result won't store the accurate value (reads 0). I divided the prior variable by 10 to see if that would compute ...
user avatar
0votes
0answers
22views

fwrite() modifying a file in place without fflush() lead to error

write_test() reads file contents and write it back just in place, why would it fail without calling fflush()? Without calling fflush(), file contents would be in a mess if the file size is several ...
user avatar
0votes
1answer
13views

C - "Run-Time Check Failure #2 - Stack around the variable 'cstringValue' was corrupted."

This code is to check whether the length of the user input is within the range of the lower and the upper limit. Or if upper limit and the lower limt are equal, testing whether the string length equal ...
user avatar
  • 1
0votes
2answers
31views

Segmentation Fault in C when adding an element to array

I am trying to calculate result of the floor function for floats <= 9999. #include <stdlib.h> include <stdio.h> #include "string.h" int main(int argc, char* argv[]) { int i,...
user avatar
0votes
0answers
13views

How to optimize N-queen with openmp - C

I am learning OpenMP and found the following code to solve N-Queens problem. I want to make faster solution with parallel code, but I don't know how to do it. Everytime I tried something, it is only ...
user avatar
1vote
2answers
29views

reversing the string without any predefined function in c

i am using below code, i don't knw what i doing wrong. #include <stdio.h> void main() { char a[5]; char ptr[5] = "hello"; int i,j,k=0; for(i=0;ptr[i] !='\0'&&...
user avatar
0votes
1answer
19views

Weird allignment behaviour in C

#include <stdio.h> int main(void) { int a = 0x4565; long ch1; int ch2; printf("%p %p %p\n", &ch2, &ch1, &a); printf("%zu %zu %zu\n", sizeof(long), ...
user avatar
  • 139
0votes
1answer
31views

How to access linked list node from other function?

Hey im trying to make a linked list. I created linked list from other function called CreateLibrary. but then how can I access the head of the node of the linked list from other function? int *...
user avatar
  • 13
0votes
1answer
41views

Why is my program returning the wrong value?

I'm trying to write a program that takes a string as an input, and returns any characters in the string which occur more than once, along with how frequently they occur. What I haven't been able to ...
user avatar
  • 1
-1votes
0answers
20views

focus does not go to the terminal window after run code in vs code

I want help related to vs code. Whenever I run the code the cursor stays in the editor (the editor stays focused instead of the terminal) and focus will not go to the terminal window without clicking ...
user avatar
0votes
1answer
19views

WIN32 and UNIX don't change in CMake cross-compile

I made a test CMakeLists.txt. I set system name and version before reading variables (although I didn't set the compiler): cmake_minimum_required(VERSION 3.10) project(test) include_directories(.) ...
user avatar
0votes
0answers
18views

Cannot include library when installing external library in c

I am setting up SDL2 in vscode, I use Makefile to include header files and lib files. The problem is vscode cannot detect the .a file, it skips the file and show this error: C:/msys64/mingw64/bin/../...
user avatar
  • 121
0votes
1answer
22views

Trying to implement a spin-lock via "lock xchg" assembly

Basically, I'm trying to run void spinlock_counter(int) in two threads and count ought to be 2000(parameter doesn't do anything I'm just too lazy). However I made a breakpoint in the critical zone i.e....
user avatar
  • 3
-1votes
1answer
32views

Bubble-sort program returns random numbers

I'm learning C and my bubble sort code returns a random number sometimes (although sometimes it does returns the correct array numbers). For example, it should print {0, 1, 3, 10}. But sometimes ...
user avatar
-1votes
1answer
30views

What is the ideal way to declare a const string as a struct member in C?

I have an object with member title, which I would like to treat as a mutable string. In this example, it would only be valid if I set the array to a fixed size, but I'm reading xml and can't decide on ...
user avatar
  • 138
0votes
1answer
18views

How to declare multiple register variables in one line in c?

I'm implementing destroy method for a linked list by keeping pointers to previous and current nodes. I'd like to declare them as register variables in a single line. Is it possible? void list_destroy(...
user avatar
  • 4,219
0votes
1answer
43views

What is this weird output after using pointer Arithemtic in C?

My goal in the code is to parse some sort of input into words regarding all spaces but at the same time use those spaces to signify a change in words. The logic here is that anytime it encounters a ...
user avatar
-1votes
0answers
32views

Pointer Array Won't Print C

I'm following an exercise on how to make pointer arrays that can store dynamically allocated strings and I'm not understanding why the following code isn't working. #include <stdio.h> #include &...
user avatar
-1votes
0answers
17views

Variable declaration not done still showing value [duplicate]

When this code is run i am getting the value 016 , can anyone explain why , even when the value is not declared ? I just have a curiosity , to find why its so ? The code was ran in codeblocks. #...
user avatar
0votes
0answers
20views

implicit declaration of function 'runProcessForOneTimeStep' - Multi Level Queue Schedular

I have been stuck with this code for some time and wanted some expert help. Below is part of my code and where the error is coming from: char* simulateNextTimeStep( schedule *ps ) { queueType temp,...
user avatar
  • 13
2votes
3answers
40views

What is the best way to match a string to specified format?

The format that I want to match the string to is "from:<%s>" or "FROM:<%s>". The %s can be any length of characters representing an email address. I have been using ...
user avatar
1vote
3answers
66views

Reading a 64 bit variable that is updated by an ISR

I am not finding much material on non-atomic operations. Suppose I have a 32 bit processor and I want to keep count of microseconds in a 64 bit variable. An interrupt will update the variable every ...
user avatar
  • 33
1vote
1answer
30views

Passing argument 3 of ‘fgets’ from incompatible pointer type [enabled by default]

I am a complete rookie to programming in C and have been trying to program a system that will take an integer input, perform a calculation, and tack them onto a string that will then be passed to a ...
user avatar
  • 13
1vote
1answer
34views

I am writing a lex code in which the regular expression section is given exactly like in the detailed section. Main problem I have is the RE for text

%{ #define FUNCT 300 #define IDENTIFIER 301 #define ASSGN 302 #define INTEGER 303 #define PRINT 304 #define TEXT 305 #define INPUT 306 ...
user avatar
1vote
1answer
47views

Question about a weird problem in functions in C language?

When calling the function billCalculator and giving it getExtraDrinks and getExtraSandwiches as arguments ,for some reason it is taking the 2nd argument first. This is the code : #include<stdio.h&...
user avatar
  • 11
0votes
1answer
22views

Creating and passing multiple pthreads in C

I'm trying to get pthread to output a variable declared in a for loop: pthread_t pthread[10]; void * count(void* argv){ int index = *(int*)argv; printf("%d", index); ...
user avatar
  • 3
1vote
0answers
41views

Is there C function to handle any shell history?

I wrote a command-line tool in C/C++. When it quit, I need to add a line to the current shell history. For now, I wrap my tool in a shell command, using history -w and history -r for bash or fc -W and ...
user avatar
  • 1,538
0votes
2answers
23views

assignment makes integer from pointer without a cast [-Werror=int-conversion]

Im trying to copy a char array to a bidimensional char array, but i keep getting this error message: assignment makes integer from pointer without a cast [-Werror=int-conversion]. It's weird because ...
user avatar
  • 3
0votes
1answer
19views

Pass multidimensional Array as parameter to function [duplicate]

I am writing a basic menu system for a TTGO-T to be able to select between different functions, I am trying to pass a multidimensional(2D) array of strings to a function(drawMenu & updateMenu). Ex:...
user avatar
  • 3
1vote
3answers
46views

I am not understanding why my recursive function is not behaving as I expect

I am trying to create a function that returns the position of the right most position of a given integer in an array. Example: [1,2,3,4,5,6] find right most position of 4 would return 4. [1,2,3,4,4,4,...
user avatar
1vote
0answers
10views

call shared library from shared library - works in C but crash with python (ctypes)

I'm calling function clGetPlatformIDs() from libOpenCL library inside my own library lib_fft3d. When I write an application which use lib_fft3d.so in C language and run it, it works just fine. ...
user avatar
0votes
0answers
38views

fopen() crashes the console

I'm relatively new to C and was working on a project to get a hang of it. I started to do a contact saving app, however, it crashes whenever I try to save the input data. The file exists, because it ...
user avatar
  • 1
0votes
0answers
29views

"space" between variables not being constant between compilers

im trying to play with pointers in c, im trying to understand how the memory gets allocated. #include <stdio.h> int main() { int num1 = 1; int num2 = 2; int num3 = 3; int num[3] ...
user avatar
  • 1
1vote
1answer
20views

Can't redirect printf to pipe

I want to redirect the output of printf to a pipe, but for some reason it doesn't seem to work. What does work is using write instead. This is my program #include <stdio.h> #include <stdlib.h&...
user avatar
  • 414
0votes
2answers
29views

check the type of array

I have 2 arrays int and float,one is commented, I would like to check the type of these arrays if int it should send to fun1() otherwise to fun2(): How can I check the type of array? int arr[]={4,6,7,...
user avatar
  • 173
0votes
1answer
25views

I don't know why my code can't handle non numeric keys

please I'm having this issue with my code. it keeps telling me that it can't handle a non numeric key each time a run a test on the program using cs50...... for(int i = 0; i < text[i]; i++) { ...
user avatar
  • 3
-1votes
0answers
18views

Finding sooner dates in c with structures [duplicate]

I wrote the most part of it buy I keep getting errors and wondering where the mistakes are. #include<stdio.h> struct d { int day, month, year; }d1,d2; int dates(struct d d1,struct d d2); ...
user avatar
-2votes
0answers
41views

Why is VS Code showing this? [closed]

I installed the Code Runner, C/C++ Extensions and the clang compiler, but when i tried to print "Hello World" either in C or C++, VSCode showed this error. Can anyone help? " Undefined ...
user avatar
-4votes
1answer
52views

Why is Q equal to 65 when assigned to a char in C language?

I am learning C language from an online textbook. I have experience with C++ and the datatypes that are used. However, in the C textbook that I am using, one of the assignments is: char letter = Q ...
user avatar
-2votes
0answers
13views

I'm in B.Tech 1st Year . While finding 2nd largest among 4 numbers using if else only, the code is malfunctioning sometimes while running

I found largest among 4. Then made 4 cases as the largest number can be anything from a to d . When a is largest we will compare b/w b, c & d. // The larger no. among b,c & d is the 2nd ...
user avatar
1vote
2answers
33views

expected a type specifier in C

All of my programs before have been working well with C except for today. For some reason I keep getting "expected a type specifier" I am confused why this is not working. #include <stdio....
user avatar
0votes
1answer
21views

Wierd error while compiling my program and a module using makefile

This is the error when I run make: Undefined symbols for architecture arm64: "\_add", referenced from: \_main in a4-1-989722.o ld: symbol(s) not found for architecture arm64 clang: error: ...
user avatar
2votes
0answers
31views

Is it possible to auto split the .text section across mulitple memory areas?

I am currently writting a embedded program for a microcontroller with a splitted flash region. Something like MEMORY { flash1 : ORIGIN = 0x1000, LENGTH = 0x1000 /* 1K gap */ flash2 : ...
user avatar
0votes
2answers
55views

Checking the dates in c

I am writing a program which checks two dates but ı am having problems while doing that. program takes two dates as input and gives an output like this: date:7/9/12 date:5/4/20 7/9/12 is sooner. #...
user avatar
0votes
0answers
23views

How do I call a function when the argument uses a double pointer or pointer? [closed]

#include <stdio.h> void swap(int** first, int** second); int main(void) { int num1, num2; int* ptrnum1, * ptrnum2; num1 = 10; num2 = 20; ptrnum1 = &num1; ptrnum2 = &...
user avatar
  • 1

15 30 50 per page
1
2 3 4 5
7531