C is a general-purpose computer programming language used for operating systems, games and other high performance work.

learn more… | top users | synonyms

-1
votes
0answers
17 views

Get defines dynamically for messages

In this following code, i want to use predefined message for my errors_manager function, with the macro CALL_MSG(). but when i use an variable, i can't get the content of the variable ! err = ILLOPS ...
-2
votes
2answers
43 views

Using a global struct with pthreads in C [on hold]

I'm trying to simulate clients going into a bank and being served by tellers over a period of time. I am using a thread to determine if a client came into the bank via an arrival rate and am using ...
-1
votes
0answers
33 views

Rolling a Parser for the Build Your Own Lisp Book? [on hold]

Hello I am currently reading the Build Your Own Lisp book online and have reached the parsing chapter. I am enjoying the book very much, but instead of using the author's parser I would like to roll ...
-5
votes
3answers
58 views

Some tips on creating programs in C? [on hold]

So I'm currently in my first year in university studying electrical engineering. I'm taking a intro to C course, and I'll say it now, I'm not sure if I'm going to be able to pass the exam. Even with ...
-1
votes
0answers
3 views

convert string to integer does not work for nagative case C programming [migrated]

I have some homework in which the first step is converting the input string into an integer. Example when I input "1 2 3 4" then its output is : 1 2 3 4, or input is: a1b3c 4 then output is 1 3 4. ...
0
votes
0answers
5 views

Complex Data Type in C Producing Trouble in Algorithm [migrated]

I'm trying to perform a calculation which involves the following C-function: long double complex* tridiag_thomas(long double complex *a, long double complex *b, long double complex *c, long double ...
2
votes
1answer
93 views

Exceptions in ANSI C

Would it be possible to implement exception mechanism in pure ANSI C similar to the one used in popular OOP languages (with familiar try-catch-finally clauses)? If yes then how? I'm especially ...
-2
votes
1answer
79 views

Learning C as my first Programming Language [closed]

I am Very new to programming and i am Learning C, My Question is: I am learning from book (C Primer Plus: Edition 5 by Stephen Prata) at home. Will i get enough grip over C language if i learn from ...
-5
votes
0answers
31 views

Write a program which recurrently move to right elements of array by given number [closed]

Write a program which recurrently move to right elements of array by given number.For example for array {1, 2, 3, 4, 5, 6} and moved by 2 it should look like that {5, 6, 1, 2, 3, 4}. ` #include ...
-5
votes
0answers
38 views

How to use C to communicate wirelessly [closed]

Is there away to get c to communicate on a standard windows computer? This would just be a simple program that can send messages back and forth. If anyone knows tutorials for things like this, can you ...
0
votes
0answers
38 views

type name for state machine state (as opposed to other state variables)

I need to create a typedef for a state machine state, e.g. enum ToasterStateMachineState { TSM_READY, TSM_TOASTING, TSM_DONE }; But ToasterStateMachineState seems verbose and redundant; is ...
4
votes
1answer
105 views

What is grouping?

In the introduction to K&R there is the following text: Similarly, C offers only straightforward, single-thread control flow: tests, loops, grouping, and subprograms, but not ...
-1
votes
0answers
13 views

How to stop copying into array using fscanf when its the end of the line? [migrated]

I have a file that has lines like Bob, 2,3,13,4 Jim 3,4,15,3 ... and I'm trying to copy into my numbers array only the integers in each line, so that I could do some math with them. Problem is, I ...
-2
votes
0answers
32 views

Help on Serial print (Arduino C) [migrated]

void loop() { photoCell = analogRead(pin); time = millis(); if (photoCell >= 400){ timeon = millis(); led = 1; while (analogRead(pin) >= 400) { timer = millis() - timeon; ...
0
votes
0answers
3 views

updating multidimensional pointers for radix buckets [migrated]

First post on Stackexchange, so - hi everyone. I'll give a short background to my situation: Our professor isn't really helpful and doesn't quite know his things well, especially when it comes to ...
0
votes
0answers
19 views

Issues while dealing with an array in C [migrated]

iI'm trying to understand how to properly use arrays in C and tried to write a simple program, which is supposed to take a 5-integers array and eliminate zeroes to the left. This is my attempt: ...
0
votes
3answers
127 views

Socket Connecting to Large number of IPs

I have a text file of ~600 CIDR notation IP blocks which, when expanded, amount to ~17.5M IP addresses. I need to socket connect to each one. If it connects, I add it to a "live" list, if it returns ...
0
votes
0answers
55 views

Does multiple Bloom filters make sense?

In order to decrease the number of false positives, I came up with a couple of possible solutions. Create two different types of Bloom filters; eg. filter1 using 3 different hash algorithms, filter2 ...
-1
votes
1answer
58 views

How implement a doubly linked list using single pointer inside? [closed]

struct{ int value; int *pointer; } I want to make doubly linked list using the above structure.
1
vote
3answers
225 views

Including extra headers that I do not really need

I always wondered what are the effects of including not needed headers to the final executable once compiled. In my code some times I may included many different headers that I do not need (or I used ...
2
votes
1answer
181 views

Quickest sorting algorithm for sorting a low number of integers

I am making a program on my spare time that I want to run as quickly as possible. The program is written in C. A large set of the procedures operate on pointers to 7 integers that are sorted by their ...
23
votes
7answers
2k views

Is it good practice to rely on headers being included transitively?

I'm cleaning up the includes in a C++ project I'm working on, and I keep wondering whether or not I should explicitly include all headers used directly in a particular file, or whether I should only ...
1
vote
1answer
72 views

Holding of files being edited in a text editor

I'm writing an implementation of Ex (hopefully Vi eventually) as a personal project. I need to somehow store an identifier for the file associated with each buffer. In terms of security/race ...
0
votes
0answers
71 views

In-place merging of sorted intervals in an array?

So I have code producing k sorted intervals in an n-sized array. What I'm brainstorming is the possibility of in-place merge of these intervals into a single sorted interval/array. The problem is ...
4
votes
2answers
158 views

When should a trig function, with a degree argument, return -0.0?

In creating trig functions my_sind(d), my_cosd(d), my_tand(d), that used a degree argument rather than a radian one and provided exact answers at multiples of 90, I noticed that the result was ...
0
votes
3answers
113 views

Alternative to printing debug information to stdout\stderr [duplicate]

I currently have a long running application on an embedded Linux environment and all debug messages are currently being outputted to stdout using printf. This isn't ideal for special users who ...
6
votes
1answer
196 views

Do any notable C extensions include integer types that are independent of machine word size

An interesting characteristic of C compared with some other languages is that many of its data types are based upon the word size of the target architecture, rather than being specified in absolute ...
1
vote
2answers
356 views

Generics in low level languages

I'm developing a language like Vala and OOC that compiles back to C. This means that, eventually, every feature needs to be adoptable to C code in some way or another. Generics is one of the features ...
7
votes
2answers
192 views

Autoreleasing objects in Reference Counting Systems

I'm experimenting a bit in C and I'm trying to implement my own Reference Counting System. I've mainly worked with Objective-C in the past but AFAIK autoreleasing objects is something that is unique ...
1
vote
0answers
65 views

Is conversion from C/C++ to Verilog/VHDL for FPGA a derivative work? [duplicate]

Say I have a C/C++ software licensed under GPL that gets converted into hardware design. By this conversion I mean that the exact functionality of the original software is being programmed into an ...
-3
votes
0answers
27 views

swig can't generate wrap c file for android [migrated]

I am working on Fedora 20 and I installed swig. I want to write C Hello World program and it run on Android tablet. When execute instructions from official site of swig in subject 'SWIG and Android', ...
1
vote
0answers
37 views

Qt: internationalization of images [migrated]

I am aware of utilities like GNU gettext for making the software multilingual. You give it a string id and it will return the translated string. But I also need this for images in Qt. For example, if ...
-4
votes
0answers
43 views

Passing 2 dimensional array created using dynamic memory allocation [migrated]

I've created a 2-D array in C using dynamic memory allocation. int **x; x=(int **)malloc(2*sizeof(int)); for(i=0;i<k;i++) x[i]=(int*)malloc(K*sizeof(int)); Now, let us pass this array as a ...
0
votes
0answers
83 views

How increment ++ really works and how to adapt it to exclude an invalidity? [migrated]

The context: As part of a class project, I created this code (Original Version). It works great, had almost full grade. As I was learning new materials, I challenge myself to rewrite the original ...
-4
votes
0answers
41 views

why pointer variable not showing 100 digits? [migrated]

aim: i had a requirement for accuracy i need 100 digits to be displayed try 1: first i had used integer variable then it displayed only 10 digits try 2: with the help of my friend i used pointers ...
3
votes
6answers
234 views

Explicitly define enum values, even if the default value is the same?

There are times when an enum's values are important: it is not necessary for them to be unique, they also need to have specific values. In such cases, should the values be explicitly defined, even if ...
0
votes
2answers
72 views

Return equal occurrence of char in a list of strings

I have an array of strings ["abb", "bbxxaa"]. I would like to print all characters that occur equal times in each index so in above case I would print bb because they occur twice in both indexes and ...
0
votes
2answers
134 views

C Linked List Implementation Pointer vs. Pointer-to-Pointer Consistency

To get some practice in C, I'm writing some basic functions for operating on a linked list of ints. I started out with functions that accepted as a "list" a pointer to the head node. Now, I find ...
2
votes
2answers
62 views

API to get data, caller may not know how much? How to allocate buffer size

I am writing a C API for retrieving data from a hardware device. The data will be returned as a string with approximately 30 bytes of text per item. The problem is there may any number of items. ...
5
votes
4answers
506 views

When does it make sense to compile my own language to C code first?

When designing an own programming language, when does it make sense to write a converter that takes the source code and converts it to C or C++ code so that I can use an existing compiler like gcc to ...
3
votes
3answers
375 views

Separating Code into Smaller Files in C

I am in the process of cleaning up my code and making it easier to maintain. I am doing this by turning my 5000+ line file into separate smaller files. I have successfully created separate source and ...
-3
votes
1answer
110 views

Illustrate Meaning of : gcc -g programName.c

To debug a C program using gdb effectively it is required to compile it first using the command: gcc -g programName.c otherwise on using simply gcc programName.c and running we are unable to ...
0
votes
1answer
161 views

What are the current (2014) naming conventions in C for file names? [closed]

This is about C, not C++. Googling this brings this result up immediately: https://www.doc.ic.ac.uk/lab/cplus/cstyle.html#N10081. In that article, the authors are saying very clearly that all source ...
1
vote
2answers
148 views

Given a number X, how do I find from an array of numbers, a unique combination that adds up to X and has the lowest sum of squares?

Given the number 15 and the array [1, 2, 3, 4, 5, 6] Possible combinations (sum=15) would be: [1, 2, 3, 4, 5] [2, 3, 4, 6] [1, 3, 5, 6] [4, 5, 6] Their respective sum of squares would be: 55, 65, 71 ...
1
vote
2answers
200 views

Infinite while loop CPU usage

I'm coding an script in C, which is going to check constantly an array of events, the idea is to check if the Date and time of certain event is equal to de current time and trigger something, i'm ...
0
votes
3answers
99 views

Does it make sense to have a separate init function?

I'm created an opaque type and I have two options for its management. The first looks like this: type_t *a = type_init(); int err; err = type_do(a, "foo", "bar", FLAGBIT1|FLAGBIT2, NULL); if (!err) ...
1
vote
1answer
129 views

The advantage of using __attribute__((aligned( )))

I found in more than one SIMD program the instruction __attribute__((aligned(16))) . When I looked for an explanation I found The keyword attribute allows you to specify special attributes of ...
7
votes
5answers
587 views

Undefined behavior, in principle

Whether in C or C++, I think that this illegal program, whose behavior according to the C or C++ standard is undefined, is interesting: #include <stdio.h> int foo() { int a; const int ...
1
vote
3answers
195 views

How to abide the “allocate in caller” rule when the size is computed in the callee?

Let's say we have an opaque type handle_t that is managed through a simple interface with functions such as: handle_t *handle_init(void); int handle_do(handle_t *); void handle_free(handle_t *); ...
4
votes
2answers
107 views

Defining error codes

We are designing an error-handling framework for a cryptographic library written in C. The approach we are taking is that relatively few errors are propagated back to the user since on most occasions ...