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
0
votes
0answers
4 views

How do i check for a specific text in a file?

So i'm reading a a txt file in c. using fgets(Array[100], 100, File); then i need to test if it contains a specific text such as Cow, i need to set Cow to be only the first character [C] and then ...
0
votes
1answer
26 views

Does WebAssembly run faster if written in C as opposed to Python?

There's a long list of languages that can be compiled into WASM. Is there any performance gain from writing in something like C or Rust over Python? Or is it all the same since it is being compiled to ...
0
votes
1answer
14 views

How to use libclang to parse c++ header?

I tried to parse a c++ header with libclang, but the parser only parsed the class name - and show its type as VarDec1. When the file extension changed from .h to .cpp, it just works fine. I couldn't ...
0
votes
1answer
18 views

Inclusion of same header file in different C files [duplicate]

I understood that an include guard prevents multiple inclusion of same header in a single .c file. What if I include X.h in A.c and B.c? Now the linker will throw a multiple inclusion error, right? If ...
1
vote
1answer
30 views

How can I read data and display them with C language?

I have to make a program which can read 'score.dat' file. Hereby, in the 'score.dat' there are 20 integers saved in binary form. Therefore, in this program when I read the 'score.dat' file I have to ...
2
votes
1answer
19 views

where does the glibc's implementation of syscall open set ENAMETOOLONG errno when pathname is too long?

From the man open: int open(const char *pathname, int flags); ... ENAMETOOLONG pathname was too long. open will be set errno to ENAMETOOLONG, but I cannot find this ...
3
votes
1answer
31 views

stat(2) and EINTR

There are some syscall-backed i/o functions (I recently found at least two: stat() and mkdir() but nearly sure that there are more) that don't have EINTR in possible errno values according to POSIX, ...
0
votes
1answer
21 views

Fscanf can't scan the values from the row properly

So I want to read the lines and save them dinamcly in a array the lines. Can you help me foind the problem, because I can't scan the last value (distance) from the line. Code: [...] typedef struct { ...
0
votes
2answers
48 views

Segmentation fault. Where am I wrong? C

I need to realize dynamic matrix in C. I have this code in main: #include <stdio.h> #include <stdlib.h> int main() { int rows, cols; scanf("%d", &rows); scanf("%d", &cols)...
-3
votes
0answers
52 views

Feature request to compiler languages(division) [closed]

I know this question can be somewhat off topic but I couldn't find the appropriate place to find my answer. Also, I know Stackoverflow, have plenty high profile programmers as member. Thus, I know ...
0
votes
1answer
28 views

Conditional expression in ternary operator in C

Code #include <stdio.h> int main() { int i; for (i=1; i<=10; i++) { (i % 2) ? printf("%d is odd\n", i) : printf("%d is even\n", i); } } Result 1 is odd 2 is even 3 is odd ...
1
vote
0answers
19 views

How can I use .bss section of memory(for global variables) for assembly(armv8) program properly?

Here's how I wrote it on my code: .section .text fmt: .string "x \t\t ln(x)\n" sfmt: .string "%.10lf \t %.10lf\n" error: .string "Error" filename: .string "input.bin" ...
-1
votes
0answers
22 views

Creating a Memory Allocation Program Using Linked List in C [closed]

I am writing a C program that implements Memory Allocation using best-fit, worst-fit and first-fit. I am supposed to use linked lists. For whatever reason, the allocation part is not working! Please ...
0
votes
0answers
29 views

c - writing counter value as integer at the very start of a new file

So I have a part of a program below that reads data from a csv file and writes the data to a new text file with alterations. I'm trying to figure out how to write an integer (count) at the very start ...
0
votes
3answers
23 views

2D struct array: swap row and col?

I want to swap the entire column and row of a 2D struct array. With this code I can swap rows: #define N 9 typedef struct { char number; bool editable; } FIELD; int main(){ FIELD **f = (...
0
votes
0answers
35 views

Function malfunction

The main() function code is supposed to call a function blah(int,int) the code apparently stops responding after the second input is taken. It doesn't even go to the printf()but in case the function ...
3
votes
2answers
42 views

Confused about understanding and silencing a -Wsign-compare gcc's warning

Here is a function i am trying to compile : static ssize_t output(t_out_buffer *buf, char const *src, size_t size) { size_t osize; osize = size; while ((size > 0) ...
0
votes
0answers
20 views

clang - Cross compile for linux on macOS

I am trying to cross compile for linux on macOS. I keep getting ld: unknown option: --eh-frame-hdr when using the default toolchain. Is cross-compilation not really possible on macOS by default? Do I ...
0
votes
1answer
40 views

Why does my program work in C but not in Matlab

Why won't this program work in Matlab, while it does work in C? Let me explain. I got the C code to solve the exercise I was describing here working. I constitute the vector Ps_trace by taking the ...
0
votes
2answers
54 views

How do I reverse only the last 8 bits of an integer (32 bit) in C?

I have implemented the below function in C but it is not working properly. int reverse(int org_num){ int rev_num=0; int i=1; while(i<=8){ int last_bit=org_num&1; rev_num=...
0
votes
0answers
16 views

Change function name when over RPC

So I am looking to create an RPC system, but self-contained in a single C app using winAPI: Basically the difference between server and client would be command-line arguments (--server and --client), ...
0
votes
0answers
24 views

Link grep as static library linux

I know I need to build grep without linking, and change grep main function name to sth different. Then from object files create lib which I should link. This sound easy in theory, but does anybody ...
0
votes
2answers
28 views

reversing words in a string in c

I have homework assignment: to write a function that reverse a string, and then write a function that reverses words in a string, using the first function. So if the input is: "have a nice day", the ...
-1
votes
0answers
18 views

How to split elements from an array which has numbers with space and these elements become independent numbers in new array [closed]

I'm beginner and starting to learn C. Now i'm having a problem of creating another array from the original array which has elements in it with space. For example -> array[]="123 234 45" then the new ...
-2
votes
0answers
32 views

How to call ASCII characteres to fill the array words [closed]

char menu[50][50] = { "Abrir ficheiro de amostras ", "Aplicar retifica%c%co de meia onda ", "Aplicar retifica%c%co de onda completa ", "Aplicar filtro RC ...
-1
votes
0answers
7 views

How do I write to the Windows Event Log from an ISAPI Extension

I wrote an ISAPI Extension for IIS in regular C. I am trying to add the ability to write error messages to the event log. I have done this from a Windows Service written in C so I have some knowledge ...
0
votes
0answers
28 views

How would I go about passing information to another thread in C? [duplicate]

I have an assignment where I need to create 2 processes, a producer process and a consumer process. Both the producer and consumer then need to create 5 threads each. The 5 producer threads each read ...
-1
votes
0answers
20 views

Conditional message send from server to client in C [closed]

I am implementing a multiple client server anagram game in C. unfortunately I cannot share my code with you because it is a school assignment and it needs to be private. So basically this server ...
-3
votes
0answers
33 views

Sorting an array using binary sorting method [closed]

The binary sort is a way of quick sorting and its feature is it is so fast in comparison with other sorting algorithms. This algorithm based on making a list of the elements as a truth table and ...
0
votes
1answer
47 views

Valgrind throws invalid free() when I try to free an array of dynamically allocated pointers

I'm allocating an array of pointers that are dynamically allocated and I try to free them at the end of my program. The problem is that I always get a "invalid free()" error on valgrind, though I ...
-1
votes
0answers
75 views

C - Incorrect values in array

I have a function knn() that traverses a kd-tree and attempts to before "k nearest neighbor" search based on the kd-tree structure. All functions such as insert, traverse, delete, minimum are unit ...
0
votes
0answers
22 views

Printing Unicode Characters from scratch C linux [duplicate]

So my question is, how do I print Unicode characters to the Linux Terminal with the write() syscall from <unistd.h>. I don't want to use higher level libraries like <stdio.h> or <...
2
votes
0answers
21 views

How to restore terminal colours when closing ncurses

I am developing an ncurses program that makes use of init_color to set custom colours. In order to restore terminal colours when the program ends, I have used color_content to store the colours at the ...
0
votes
1answer
22 views

c - writing float values from csv file into new file & iterating through field

So basically I have a separate csv file filled with different columns that focuses on icecream toppings and specific sizes/measurements. In my program called convert.c I'm trying to write a program ...
2
votes
2answers
52 views

Wrapping a C program that contains a main function into a C++ class,

I am recently asked to wrap a C program that contains a main function into a C++ class, but I do not see the general approach to do it effectively. For example, my C program is #include<stdio.h&...
0
votes
3answers
39 views

Palindrome, to lower function

Currently have a assignment from school to make a C program that checks if a user entered string is a palindrome or not. The program need to have 2 different functions (not counting the main function) ...
1
vote
0answers
25 views

Hide private fields of a Rust lib when generating its C header

I am making a Rust library that contains the following code: pub mod my_module{ use std::os::raw::{c_int, c_double}; use std::collections::HashMap; struct MyPrivateClass { ...
0
votes
3answers
42 views

getting segmentation error (core dumped) in linked list

I have looked at my code several times but couldn't find the problem. please tell me what I need to replace to get my code working. #include <stdio.h> #include <stdlib.h> #include <...
0
votes
1answer
34 views

Finding Items in Struct and edit them

i have a problem in my code (Case 2), I try to get the position of the item what I get from the scanf() but when I try to get the position it give me a complete random number like 537890. I can't ...
0
votes
0answers
20 views

changing time-slot in RR scheduling XV6

I wanted to customize the current round robin scheduling algorithm used in xv6 to give each process multiple time slots instead of only one time slot.
0
votes
1answer
53 views

Why would I get 8 hex digits when I specify “%.2x”

I want to print the hex representation of a floating-point number, but there are some fs being printed unexpectedly. Here is the code I'm using: float f = 0.2; char *ptr = (char*)&f; for (int i ...
1
vote
0answers
30 views

getting the size of a struct without the last member [duplicate]

suppose I have the following struct declaration struct m27 { uint64_t head ; int vp_array[500] ; float lpx[500] ; s_ent ent[500*plno] ; uint32_t crc ; }; prior to writing to disk or transmitting ...
0
votes
1answer
26 views

Randomized QuickSort with double linked lists

I am trying to implement the randomized quicksort algorithm to work with double linked lists and I am doing something wrong. For some reason the randomizedQuickSortList() recalls itself 32369 times ...
0
votes
0answers
28 views

why this program need more than 47 input to occur buffer overflow?

Why this program needs more than 47 input to occur buffer overflow? #include <stdio.h> #include <string.h> int main(int argc, char *argv[]) { char whatever[20]; ...
0
votes
0answers
23 views

Ajuda para debugar no Visual Studio [closed]

Existe alguma maneira no visual studio de ir de um breakpoint para outro ignorando tudo o que estiver entre eles? Eu possuo um sistema gigante e complexo, que quase sempre para chegar até onde eu ...
-3
votes
0answers
50 views

I am making an os, and ran into an error. please help! I have no clue [closed]

When I try to compile link.ld, [below], it throws an error. ;link.ld OUTPUT_FORMAT(elf32-i386) ENTRY(start) SECTIONS { . = 0x100000 .text : { *(.text) } .data : { *(.data) ...
-4
votes
2answers
95 views

Why can't I initiate a string variable with another? [closed]

I'm trying to sort an array of strings but it says I have memory problem for x void arrange(char*** tab,int n) { char* x; int j; for (int i = 0; i <n-1 ; i++) { x=(char*)malloc(...
0
votes
0answers
39 views

Why when i try to display an int*, it display a addition of all previous element

I've got a problem, when i try to display a int* with simple function it acts weirdly, like: ./program 10 10 10 got : "20, 30, 0," And I have absolutetly no idea why... void display(int *arr, int ...
-3
votes
2answers
45 views

Memory corruption of dynamic array in struct?

So I have these two structs. Only need to worry about these three variables; name_size, name and xattrs[0]. typedef struct dxattr { unsigned int name_size; /* length of name string in ...
0
votes
1answer
16 views

c - how to access defined values in separate header file

So I have a separate file called simulator.h with defined values such as: #define PEPPERONI 1 #define CHEESE 2 #define VEGETARIAN 3 I have a separate csv file filled with a column of ...