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

learn more… | top users | synonyms

2
votes
2answers
85 views

Why define struct in variable?

Consider the following program: Many people when they want to use a struct, they create a new variable as: struct structureName variableName While it works when you just define it as: ...
-4
votes
0answers
45 views

Replace tabs with spaces in C [on hold]

i want to replace tabs with spaces but i didn't get it. I have an file pointer which i give into the function and there are some \t and i want to replace them with as many spaces as needed. For ...
-4
votes
0answers
48 views

C application vs C++ application [on hold]

What are a real life application that is based on C language rather than C++? Why is it using C and not C++ since they are almost the same? Do you think we can convert that application to C++? And how ...
-3
votes
1answer
30 views

How can this allocation of bi-dimensional arrays work?

I was seeing this post on StackOverflow and saw a new way (at least for me) to define a two dimensional array of 5x5, it works well, but I feel I don't understand what is going on in the background. ...
-2
votes
0answers
58 views

Is the time complexity of this code snippet O(n)? [migrated]

struct lists * list_depth[ht]; for(int i=0; i<ht; i++) list_depth[i]=NULL; insert_to_list(&list_depth[0], root); for( int i = 1; i < ht; i++ ) { struct lists * temp = ...
-4
votes
0answers
42 views

Custom code folding in Eclipse

For those who use Eclipse and are working primarily in Java, there is a custom folding plugin coffee script. It is old but still works. However, C/C++ users are left without code folding ...
-2
votes
0answers
32 views

Find the number of increasing Sequence of length K

Let we are giving a Array we have to find the number of increasing sequence of length K. 1 2 3 1 1 For the first window of [1, 2, 3], there are 3 non-decreasing subranges so the answer is 3. For ...
-1
votes
1answer
93 views

Is there a practical use case for 5 stars (pointer to a pointer to …) [on hold]

I know of practical use cases of 3 stars (e.g. char*** test), I've seen one of 4 stars, but is there a practical use case for 5 stars that couldn't be made (elegantly) using less?
1
vote
3answers
118 views

Use of for loop conditional statement unrelated to iterating variable

Is it considered decent form to write code like this: int done = 0; for (x = 0; !done; x++) { ... something involving 'x', that might end early ... if (!(x < max)) done = 1; } ...
-3
votes
0answers
56 views

Are there any tools that calculate the stability metrics for a C code base? [closed]

I am looking for static analysis tools which calculate the (in)stability* of various modules in a C code base; similar to how a tool like CCCC calculates the McCabe complexity of a code base. * ...
-2
votes
0answers
31 views

A library to be able to reproduce mp3 files in Raspberry Pi [closed]

I've been having a hard time looking for a simple library to reproduce audio files (mp3 precisely) , i've tried pyglet for python, but didn't succeed, but look, the only thing i want/need is a library ...
1
vote
3answers
72 views

Question about multidimensional arrays

I was wondering something about the multidimensional arrays and then I got a doubt about a concept, specifically about their representation on memory. For example, an array can be defined as follows. ...
-2
votes
0answers
73 views

How can I run the FOR loop for more than the size of long long int [closed]

for(i=0;i<pow(2,N);i++) { //code goes here } N=1000, i.e pow(2,1000)>10300 but long long int can only hold upto 1018. How can I be able to run this for loop.
1
vote
2answers
206 views

Searching algorithm used in switch statement

What is the searching algorithm used in switch statement in C language? If the cases are not in order still it searches proper case which means it is not a binary search algorithm, can anybody ...
-3
votes
0answers
109 views

Why GCC does this? [closed]

I've been programming in C for a long time, but I've never worried about the issue about what are the differences between the standards or anything like that, but now I wanted to investigate to learn ...
-4
votes
0answers
27 views

good C library to detect collision of 2d shapes [closed]

I'm looking for a C library to detect collision 2 shapes in 2D. I have shapes in svg or besier lines
0
votes
1answer
106 views

Introducing function waypoints to protect device [closed]

Defining a magic pointer or counter inside a program / class and checking for a fixed value before executing critical commands is a way to generate a barrier against wrong execution. This check is ...
-2
votes
1answer
74 views

Printing value of atoi of an array - what does the number mean? [closed]

Simple question, below is my code. The number my compiler returns is 4219296. My question is: why? What is my code doing here? #include <stdio.h> int array[]; int main() { atoi(array); ...
15
votes
3answers
1k views

Why do we have to mention the data type of the variable in C

Usually in C, we have to tell the computer the type of data in variable declaration. E.g. in the following program, I want to print the sum of two floating point numbers X and Y. ...
0
votes
0answers
17 views

Is `\n` necessary to be given to `printf()` in C [migrated]

I am reading the book "The C Programming Language" by Brian Kernighan and Dennis Ritchie. In the first article they say that one must use \n in the printf() argument, otherwise the C compile will ...
-2
votes
0answers
24 views

C - meaning of non zero adresses in nullspace [migrated]

This is a linked list queue implementation. This is my program int size(QueuePtr q) { QueuePtr temp = q->next; int size = 0; while(temp) { size++; temp ...
0
votes
0answers
6 views

Matrix Multiplication question [migrated]

So I'm trying to write a C function to calculate the multiplication of two arrays but I am a little bit stuck. double ** matrixMultiply(double **A, int nRowsOfA, int nColsOfA, double **B, int ...
0
votes
0answers
5 views

Loop in system call C program [migrated]

I want to call the function wget in a loop in ubuntu, how can I do it? This is what I did, but it didn't work. for (i = 1; i < 500; ++i) { system("wget -O page%i 'http://www.asdf.com/?=%i'", ...
3
votes
4answers
299 views

Why do we have to tell printf() the type of data in C?

Let's consider this C code: #include <stdio.h> main() { int x=5; printf("x is "); printf("%d",5); } In this, when we wrote int x=5; we told the computer that x is an integer. The ...
-1
votes
0answers
22 views

Get defines dynamically for messages [migrated]

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
67 views

Using a global struct with pthreads in C [closed]

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 ...
-5
votes
3answers
78 views

Some tips on creating programs in C? [closed]

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
113 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 ...
0
votes
0answers
40 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
108 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 ...
0
votes
3answers
134 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
57 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
64 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
233 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
194 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 ...
24
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
73 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
82 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
163 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
122 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
205 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
361 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
204 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
6answers
238 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
75 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
151 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
65 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. ...