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

learn more… | top users | synonyms

-4
votes
1answer
19 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. ...
-12
votes
0answers
48 views

Why are they still using C program [on hold]

Why are they still using C even though not OO (object oriented)?Are they using Windows or Unix Environment? If either, what are the advantages or disadvantages? What it takes to move from procedural ...
-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
37 views

Custom code folding in Eclipse

For those who use Eclipse and are working primarily in Java, there is a custom folding plugin. It is old but still works. However, C/C++ users are left without code folding customization. Eclipse CDT ...
-2
votes
0answers
31 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 ...
8
votes
3answers
838 views

Reason for placing function type and method name on different lines in C

I just started at a company and one of the style comments at my first code review was that the return type and method name should be on different lines. For example, this void foo() { } should be ...
-1
votes
1answer
91 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
117 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
55 views

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

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. * ...
1
vote
2answers
410 views

Is there a better way to organize my module tests that avoids an explosion of new source files?

I've got a neat (so I thought) way of having each of my modules produce a unit-test executable if compiled with the -DTESTMODULE flag. This flag guards a main() function that can access all static ...
-3
votes
0answers
32 views

a program to delete spaces from string [closed]

i am trying to make a program to delete spaces from string and i wrote this code and doesn't work so please see what is wrong with it #include<stdio.h> #include<conio.h> ...
-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
71 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
204 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
108 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
26 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 ...
59
votes
15answers
18k views

What makes C so popular in the age of OOP?

I code a lot in both C and C++, but did not expect C to be the second most popular language, slightly behind Java. TIOBE Programming Community Index I'm curious as to why, in this age of OOP, C 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. ...
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 ...
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 ...
38
votes
14answers
3k views

What do I need to do to NOT steal “Hello World” code with a GPL license?

In the project, I found a file, math.c, with a big GPL header and ... //------------------------------------------------------------------------------ /// Returns the minimum value between two ...
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'", ...
15
votes
6answers
1k views

Is it a good habit to use C expressions in C++ code?

At school we started learning C this year, despite the fact I'm way ahead of class, and I learned Java, C++ and C while the class is at the base of C. Anyhow, I've been documenting myself, reading ...
17
votes
3answers
3k views

How to solve the problem of nested comments

It appears in not just one language that comments can't be nested. Do you have a good solution for this problem? One workaround in C/C++ and Java is to only use the single-line comment but it becomes ...
-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
75 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
111 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 ...
56
votes
16answers
15k views

I don't know C. And why should I learn it? [closed]

My first programming language was PHP (gasp). After that I started working with JavaScript. I've recently done work in C#. I've never once looked at low or mid level languages like C. The general ...
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 ...
24
votes
10answers
8k views

Why are pointers not recommended when coding with C++

I read from somewhere that when using C++ it is recommended not to use pointers. Why is pointers such a bad idea when you are using C++. For C programmers that are used to using pointers, what is the ...
0
votes
3answers
133 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 ...
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 ...
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
63 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.
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 ...
8
votes
5answers
7k views

Why can you have the method definition inside the header file in C++ when in C you cannot?

In C, you cannot have the function definition/implementation inside the header file. However, in C++ you can have full method implementation inside the header file. Why is the behaviour different?
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 ...
2
votes
3answers
540 views

What could be the advantages and disadvantages of decay of Nd arrays to N-level pointers?

I have been thinking of a couple of possible extensions to the C language which I'd like to know the opinion of others about.1 This one is about multi-dimensional arrays. Imagine the following ...
2
votes
4answers
291 views

Integer sign and compilation via C

I'm writing a compiler that uses the time-honored strategy of using a C compiler as the back end, and I'm trying to figure out exactly how to handle integer sign. I'm using machine word integers as ...
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 ...
-2
votes
3answers
802 views

Time limit on user input

I am trying to put a time limit on the user input, so if they take longer than 2 seconds to put type in an input then the program will terminate. I was wondering if there is a simple way to do this in ...