Tagged Questions

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

learn more… | top users | synonyms

-5
votes
0answers
15 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 ...
-6
votes
0answers
33 views

Can Some One look at this [on hold]

Im making a command line version of Tick tack Toe for my class yet I keep running into the same problem it keeps stoping after player one take his first turn no player 2 no call back to player one ...
-5
votes
0answers
35 views

How to use C to communicate wirelessly [on hold]

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
37 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 ...
3
votes
1answer
88 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
32 views

C Programming Array Copying [on hold]

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

Developing a Phone OS [on hold]

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 [on hold]

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 ...
-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: ...
-1
votes
1answer
177 views

Writing an Operating System in C [closed]

I've done some research in building an OS and I know that it has to be made using the assembly language. I've also seen that it can be built using the assembly language with C/C++. I was wondering ...
0
votes
3answers
117 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
56 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
221 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
170 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
67 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
110 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
192 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
353 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
184 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
64 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
230 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
69 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
132 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
60 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
495 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
374 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
101 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
158 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
141 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
189 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
113 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
585 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
194 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
105 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 ...
-2
votes
1answer
135 views

Ambiguous If-else nested block in C without braces [closed]

Consider the following code in C: if(34) if(0) printf("Stat1"); else printf("Stat2"); Here,the first if condition is true,while the second if condition is ...
1
vote
1answer
214 views

Polymorphic engines in C and/or C++ [closed]

I stumbled across polymorphic engines and I don't know anything about them. However, I am curious about how they are written. Every example that I've looked up writes them in assembly, my assembly is ...
0
votes
1answer
75 views

Buffer-overflow vulnerabilities that a static code analyser won't pick up [closed]

I'll use FlawFinder in this example. FlawFinder is a static code "analyser" tool that examines C/C++ source files and outputs warnings/hits if a vulnerability was identified. The way it does this is ...