Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Questions tagged [c]

C is a general-purpose computer programming language used for operating systems, libraries, games and other high performance work. 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—...

2
votes
2answers
49 views

How to handle differently sized type in C library from C++

I have an external C library that I link to from C++. The library defines a struct that uses bool and includes a typedef for it for C. The problem is that this typedef uses an int, so (on my platform) ...
0
votes
0answers
3 views

Place GTK+-3.0 Window above Chromium in kiosk mode

I running chromium in kiosk mode and I would like to have some GTK windows pop up over top of the chromium window. With my current program, if I do not set the --kiosk flag my GTK windows open on top ...
2
votes
2answers
64 views

How do I create a file descriptor backed by a simple char array?

I have a function that receives a descriptor (you know, one of those things that open() and socket() spit), reads from it and does something with the data: int do_something(int fd); I want to test ...
0
votes
1answer
16 views

Storing a string of words in a data structure

I want to create a program which receives some input words from the user, stores the inputs in a data structure and then prints the data structure on a txt file. Right now i only built the part ...
-4
votes
1answer
236 views

Obfuscate C code [closed]

I came across this obfuscated code recently: #include <stdio.h> #define _____(i,s,o,g,r,a,m)(i##r##s##o) #define _ _____(m,i,n,u,a,l,s) int _() { printf("Hello World!"); return 0; } ...
4
votes
2answers
57 views

Store contents of a file with both integers and characters in C

I have a text file input.txt whose contents are of the form: 12 3 / 2 3 - 3 4 * 1 2 4 + - 5 * 7 / My end goal is to read each line of the file and evaluate the given RPN expression. I have written ...
1
vote
1answer
30 views

Returning const char * via function parameter

Trying to create a getter for const char * type where return type is not char char * (i.e. returned via parameter). However, when return from get_MyName(), ptr_name remains NULL. typedef enum {...
0
votes
1answer
32 views

Passing C structures to OpenCL kernel

I have next structure in my host program: typedef struct s_figure { cl_float reflection; cl_int color; enum e_figure type; cl_float3 vector1; cl_float3 ...
0
votes
0answers
24 views

Server Not echoing back to Client

Server.c #include<stdio.h> #include<sys/types.h> #include<unistd.h> #include<netinet/in.h> #include<arpa/inet.h> #include<sys/socket.h> ...
0
votes
1answer
57 views

Using time stamp counter and clock_gettime for cache miss

As a follow-up to this topic, in order to calculate the memory miss latency, I have wrote the following code using _mm_clflush, __rdtsc and _mm_lfence (which is based on the code from this question/...
2
votes
2answers
12k views

C Hello world: Code Blocks IDE, MinGW C compiler on windows

I can't get Code Blocks IDE to compile the hello world C program it creates when you create a new C project. I've installed MinGW and it was recognised by the IDE. But when I try to build I get the ...
3
votes
4answers
431 views

How to escape from hex to decimal

I apologise if this is an obvious question. I've been searching online for an answer to this and cannot find one. This isn't relevant to my code per se, it's a curiosity on my part. I am looking at ...
5
votes
1answer
229 views

Why is Doxygen grouping enums with the same name from different C files?

I'm using Doxygen 1.8.5 and having the same exact problem as in the following question, only the language is C and the enums are in the C files: Doxygen C# XML comments: multiply enum's with same ...
9
votes
5answers
14k views

Latitude Longitude in wrong format DDDMM.MMMM 2832.3396N

I have a gps module that gives me latitude in longitude in a weird format. DDDMM.MMMM As written on user manual, Degrees*100 + Minutes. As far as I know, It is degrees minutes seconds, and seconds ...
0
votes
1answer
2k views

libav - undefined reference to 'av_frame_alloc' and more

I am trying to compile this tutorial from the libav doc: link I changed nothing on the code! But when I compile it with: gcc test.c -lavformat -lswscale -lavdevice -lavformat -lavcodec -lavutil -...
0
votes
0answers
33 views

Searching an array for a specific character [duplicate]

I'm trying to set up a way to search for a specific character within an array. An example would be: The user enters the string "3456/3". I'd like to be able to search for the forward slash character ...
0
votes
6answers
982 views

How big can a 64 bit unsigned integer be?

I am quite clear about How big can a 64bit signed integer be? Thanks to this question and its straightforward answers. So, according to that, could I say that an unsigned int can be 2^64 - 1, rather ...
3
votes
2answers
3k views

shm_open and ftruncate() in Shared Memory Programming

I want to create a Shared Memory Object and truncate it to a specific size. SHMSIZE is defined with 512 MODE is set with S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH Here is my Code ...
0
votes
0answers
64 views

An unexpected character is printed out after output in c [duplicate]

This program counts the number of words from single input... #include <stdio.h> main() { int wordCount = 0; int input = 0; int state = 0; while ((input = getchar()) != EOF) { ...
1
vote
3answers
2k views

Linked list shows only first node element on printing

I am trying to create a linked list in order to enhance my concepts of pointers and address. I have to create linked list in following way: (1) Read all the nodes together at once at terminal. (2) ...
7
votes
3answers
132 views

Struct vs string literals? Read only vs read-write? [on hold]

Does the C99 standard permit writing to compound literals (structs)? It seems it doesn't provide writing to literal strings. I ask about this because it says in C Programming: A Modern Approach, 2nd ...
0
votes
1answer
62 views

Read input in reverse order

I am new to C. I have just learned pointers and struct.I am trying to modify the following program so that each student read is inserted at the front of the list of students, not at the end. How can I ...
1
vote
1answer
54 views

JNA How to wrap interface written in C++

I already know how to wrap an Structure , but I need some help with interfaces. The interface I want to wrap is the IImageList. But I have now clue how to create an java class out of it SOLUTION: ...
-2
votes
1answer
43 views

Assignment about '\0' [duplicate]

I met a problem with (0xC0000005) by using below code , I saw this code in Duo Security source code , Duo can run this code successfully , but when I run this code it will fail with this code the ...
1
vote
0answers
28 views

Controller Area Network Transmit on interruption STM32f4 and HAL library [on hold]

I'm working on an STM32f4 device with HAL library. I want to transmit frames on CAN on interruption but I don't know how to do that. For now, I receive on interruption on CAN and it works well. I ...
1
vote
2answers
66 views

free memory allocation after malloc

I was reading the "c primer plus" by Stephen Prata. There is sample program for linked list. The program uses malloc to allocate the memory space for a structure array, the code for the sample program ...
0
votes
2answers
26 views

Enable a linux service to show popup window

I developed an IP messenger using C language and I wish to share some of it's implementation details to make completely understand my problem. Used GTK+-2.0 library for showing GUI windows. It has a ...
3
votes
3answers
60 views

Subtracting unsigned ints in C and getting -Wconversion warnings

Consider: uint16_t x; uint16_t y; y = 0; x = y - 1; X will be some insane number. See other SO articles for the "why" and to learn about 2's compliment. (I'm not asking why this is the case. I ...
-3
votes
0answers
40 views

change printf to windows data in c? [on hold]

I know that printf is for console and now I am trying to show that same data in a window instead. I am trying to replace the printf. So the question is how do i print messages to the edit without ...
-2
votes
2answers
108 views

VS Intellisense shows escaped characters for some (not all) byte constants

In Visual Studio C++ I have defined a series of channelID constants with decimal values from 0 to 15. I have made them of type uint8_t for reasons having to do with the way they are used in the ...
1
vote
2answers
56 views

Stored struct member data via char array pointer return garbage value

I am trying to display my database data on an OLED LCD using MySQL_Connection.h and MySQL_Cursor.h by ChuckBell. The link to this library is https://github.com/ChuckBell/MySQL_Connector_Arduino> I ...
-3
votes
0answers
40 views

Reading a casual access file

I'm creating a program which should take some hotel names as inputs and print them on a dat file. My read function, which should read the file and print everything that i previously wrote on it, it's ...
2
votes
2answers
39 views

Why does `optarg` not get overwritten?

I am new to getopt(3) and looked at some examples and came across this one. These lines case 'c': cvalue = optarg; break; looked weird to me because the content of optarg does not get ...
0
votes
1answer
26 views

Problems while i'm trying to print a list

I am stuck in a problems with lists, the problem is that when i am trying to print the entire list it prints only the first node, the main goal is to have in tha main.c with only the call to the ...
3
votes
3answers
845 views

Building nested Autotools Package without Installing

What I want is to build my autotools package together with a nested autotools package. It's a static library and usually this package install the lib in your $prefix/lib folder, if you type make &&...
2
votes
3answers
325 views

Linking m5ops.h to a C project

I have a C application that is using a function from the Gem5 operations called "m5_dumpreset_stats()". So, I did the following, I included the header file of this function: #include "../gem5-stable/...
2
votes
2answers
2k views

Raw OpenGL equivillant of GLUPerspective?

how could I do the same as GluPerspective without Glu? Thanks ex: gluPerspective(45.0, (float)w / (float)h, 1.0, 200.0);
-7
votes
0answers
55 views

What does it mean that a array has to be floor? [on hold]

My book is telling me to use a array floor but isn'it floor a function? I'm confused. Please can somebody make this clear for me?
-1
votes
2answers
45 views

Understanding uint32_t char typecast (Bytes)

Lets say we have this: int main() { int32_t* value = (uint32_t*)malloc(sizeof(uint32_t)); uint32_t array[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; *value = *(uint32_t*)((char*)array + 8); ...
-3
votes
0answers
37 views

Size issue with WM_NCCALCSIZE with Qt

I would like someone to help me, I have a problem on my window without border. When it is displayed in full screen for a second time, the size of the window is not correct. She is overflowing. I ...
0
votes
1answer
42 views

pointer to anonymous struct array in c

So I have an array declared like this (it's not my code, and I will not modify it): static const struct { int gsmesc; int latin1; int utf8_int; char *utf8; ... } gsm_escapes[] = {...
0
votes
3answers
33 views

reading a file with fscanf in a for loop C

I am having a problem reading from a file, the first print outside of the loop is done correctly . but inside the for loop nothing is read from the file. I'm looking for an explanation or help if ...
0
votes
0answers
17 views

How to compile a c file using gcc in alpine container docker [on hold]

Steps i did : 1) I have pulled the image of alpine and gcc from docker hub 2) I have created a C file in alpine container (i.e in linux environment inside dirctory say ABC) Now i want to 1)To build ...
-1
votes
1answer
75 views

Scanf() not waiting for an integer input

The second time I call scanf in this program, the function doesn't wait for user input. I know with chars you have to leave a space before the format specifier (which I have tried) but can't figure ...
0
votes
0answers
40 views

I can't sum the elements of the same column of a matrix. Why? [on hold]

It's a matrix 6x5 but I'm considering the elements starting from 1, not from zero. for(j=1; j<=4; i++){ for(i=1; i<=5; i++){ tot+=sales[i][j]; } printf("%5d",...
67
votes
3answers
76k views

C struct memory layout

I have a C# background. I am very much a newbie to a low-level language like C. In C#, struct's memory is laid out by the compiler by default. The compiler can re-order data fields or pad additional ...
1
vote
2answers
58 views

Reading a matrix of numbers from a txt file

So, i created a matrix on a txt file, which looks like this: 1.0#2.2#3.4 3.4#5.5#1.0 6.6#5.5#1.0 I need my script to read each number on the line, add them and then create a new matrix with the ...
4
votes
3answers
88 views

Why do we use `const` for strings when defining with pointers in C?

I heard from a C developer that for defining arrays with pointers, we write int *const a; because arrays have variable values but constant pointers. But for strings, we write const char *s;. I didn'...
1
vote
2answers
226 views

How to integrate CMock unit test framework with Make

Is there a way around having to switch my project to use rake as its build system? I have a large project using Make as its build system and would like to add CMock functionality for unit testing (I'm ...
35
votes
7answers
31k views

How to determine if memory is aligned?

I am new to optimizing code with SSE/SSE2 instructions and until now I have not gotten very far. To my knowledge a common SSE-optimized function would look like this: void sse_func(const float* const ...