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

learn more… | top users | synonyms

0
votes
0answers
7 views

Using a global struct with pthreads in C

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
42 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
17 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 ...
-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
92 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
77 views

Learning C as my first Programming Language [on hold]

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 ...
55
votes
16answers
14k views

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

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 ...
-5
votes
0answers
31 views

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

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
103 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 ...
-2
votes
0answers
34 views

C Programming Array Copying [closed]

I have the code as: mid = 3; for(i=0;i<9;i++){ if(i == 9-mid) num[i] = mid; else num[i] = 0; printf("%d", num[i]); } which gives the result of "000000300". What ...
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 ...
-2
votes
0answers
63 views

Developing a Phone OS [closed]

I have created a project for myself: Develop my Own Operating System.. for a Mobile Phone (touch screen). I am new to this whole thing, I've started learning C and C++ but only in theory as of yet. ...
-2
votes
0answers
38 views

C: volatile struct versus volatile members of struct [closed]

Is this code: struct mystruct { int n; char c[10]; }; volatile struct mystruct x; equivalent to this one? struct mystruct { volatile int n; volatile char c[10]; }; struct mystruct ...
-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 ...
1
vote
2answers
387 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 ...
0
votes
3answers
126 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 ...
-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: ...
17
votes
3answers
2k 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
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 ...
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.
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 ...
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?
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 ...
2
votes
3answers
520 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
290 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
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 ...
-2
votes
3answers
741 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 ...
7
votes
5answers
586 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 ...
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 ...
6
votes
1answer
194 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 ...
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 ...
0
votes
3answers
111 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 ...
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
189 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', ...
-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 ...
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 ...
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 ...
3
votes
6answers
233 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 ...
-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 ...
0
votes
2answers
133 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 ...
0
votes
2answers
70 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 ...
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 *); ...