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
2answers
57 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 ...
-4
votes
0answers
45 views

Indian algorithm, what did I do wrong [migrated]

I really need your help. I'm literally frustrated by this. It's power indian algorithm What did I do wrong? #include <stdio.h> double power(double x, int y) { double num=power(x, y/2); ...
-7
votes
1answer
85 views

Environment variables in C [on hold]

How are environment variable stored in during run time on call stack? what is the difference between env and environ pointer ? I am looking for Linux and 32-bit machine
0
votes
0answers
5 views

semicolon and commna in for loops [migrated]

for( i=0, i<3, i=i+1 ) for( i=0; i<4; i++ ) I do not understand why they are same. for( i=0, i<3, i=i+1 ) will start with i=0, then i=0+1=1, i=1+1=2, i=2+1=3, then 3 is not satisfied with ...
-2
votes
0answers
91 views

How memory is allocated for c program [on hold]

How is memory allocated for a c program when it is executing? Like first environment variables then run time arguments, stack then heap etc want exactly is representation of run time memory allocation ...
0
votes
2answers
92 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 ...
-4
votes
0answers
25 views

Csharp multiple button presses [on hold]

I have a button in a program and I want it to where when I click the button it goes to page 2 but if I click it again it goes to page 3 kinda like a book.
-3
votes
0answers
47 views

adding manually written headers in C language [migrated]

I'm writing a code for a radio, which contains many child functions and header functions. I've created two headers "simulation_params.h" in which the simulation parameters can be changed, and ...
-1
votes
0answers
40 views

In C language fscanf reads last number twice [migrated]

I have written this code to read from an input file and display the numbers: #include<stdio.h> int main() { int i; FILE * f; f=fopen("inputA.txt","r"); while (!feof(f)){ fscanf(f, "%i", ...
-3
votes
0answers
19 views

C code link edit error in Visual studio 2003 [migrated]

I have installed Visual Studio 2003 in my Windows 7 system and started compiling the C code by using the NMAKE functionality. I have compiled the code with out any issues, but during the linking ...
-1
votes
1answer
101 views

dynamic memory allocation in c language [on hold]

i'm using dynamic memory allocation in c programming.. supposing i've program like this void main() { int *C; int sum; ----------- statements ----------- test(C,sum); } void test() { --------- ...
-2
votes
0answers
64 views

Why goto statement is not considered as loop in C language [duplicate]

Printing the numbers 1 to 5 using a for loop is possible, and using goto statement also is possible, but for is considered a loop and goto is not considered as loop. Why is this?
-1
votes
0answers
54 views

Problems with printf() on AVR in C with floating-point [migrated]

I've been getting back into C, and I've been working on an 'academic' exercise to sharpen some old skills again. My project revolves around the rather simple process of generating sines. I started out ...
2
votes
2answers
57 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. ...
-3
votes
0answers
39 views

C Programming reading file [migrated]

I am trying to write a very simple code to read a file. However in that file I have M_PI/2, which is pi/2. When my code reads that file it spits M_PI/2 as 0.000. How do I make my program to make it ...
5
votes
4answers
444 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
363 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
91 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
143 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
111 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
166 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 ...
-2
votes
2answers
135 views

Returning void from a function specified to return int [closed]

int count_to_ten ( int count ) { /* we only keep counting if we have a value less than ten*/ if ( count < 10 ) { printf("%d",count); count_to_ten( count + 1 ); } return; } int ...
0
votes
3answers
98 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
65 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 ...
6
votes
4answers
463 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
190 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
94 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
128 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 ...
0
votes
1answer
192 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
68 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 ...
3
votes
2answers
162 views

On concatenating adjacent string literals

C and C++ compiles adjacent string literals as a single string literal. For example this: "Some text..." "and more text" is equivalent to: "Some text...and more text" In other languages like C# ...
-2
votes
1answer
113 views

Uniqueness of for loop [closed]

How does the for loop function is implemented so that it can accept ; as parameter separator rather than , which is trivial in normal functions.
8
votes
5answers
544 views

Are C static libraries frowned upon? [closed]

There are 2 arguments for having shared libraries: It helps reduce disk space. When a shared library is updated, all the binaries depending on it get the update. There is mainly one drawback for ...
1
vote
2answers
96 views

Microchip XC8: How to pack code against an upper limit?

I have a project for a PIC16F1454 that needs some custom linking. Basically, I've separated my code into two parts that can be downloaded separately in the field and thus update (almost) all of the ...
3
votes
1answer
248 views

Why did GCC switch from Bison to a recursive descent parser for C++ and C?

Was there a language change that required it or some practical reason why Bison was no longer appropriate or optimal? I saw on wikipedia that they switched, referring to the GCC 3.4 and GCC 4.1 ...
2
votes
2answers
114 views

In which stage of compilation is “typedef” resolved by the compiler?

There are different stages of compilation Such as Preprocessing stage Syntax analysis Semantic analysis Intermediate Code generation Machine Code generation Optimization Linking My question here ...
3
votes
1answer
126 views

How to fix legacy code that uses <string.h> unsafely?

We've got a bunch of legacy code, written in straight C (some of which is K&R!), which for many, many years has been compiled using Visual C 6.0 (circa 1998) on an XP machine. We realize this is ...
3
votes
7answers
1k views

Why do we need to include the .h while everything works when including only the .cpp file?

Why do we need to include both the .h and .cpp files , while we can make it works with making just a .cpp file and then including it . For example, Creating a file.h containing declarations, then ...
18
votes
12answers
5k views

Why does void in C mean not void?

In strongly-typed languages like Java and C#, void (or Void) as a return type for a method seem to mean: This method doesn't return anything. Nothing. No return. You will not receive anything from ...
0
votes
1answer
49 views

Macro guard in Objective-C

I have noticed that many famous libraries written in Objective-C (eg. AFNetworking) use the macro guard inside their header files. Im aware that the #import directive, which works exactly like ...
-2
votes
1answer
172 views

What are steps in making an operating system in C ? [duplicate]

I am trying to make an my own OS. This is for educational purpose only, so that I get to understand the internals as well as get a good idea of low level programming. I have some prior application ...
1
vote
2answers
197 views

Is goto to improve DRY-ness OK?

My code has many checks to detect errors in various cases (many conditions would result in the same error), inside a function returning an error struct. Instead of looking like this: err_struct ...
0
votes
1answer
106 views

comparison of an unsigned variable to 0

When I execute the following loop : unsigned m; for( m = 10; m >= 0; --m ){ printf("%d\n",m); } the loop doesn't stop at m==0, it keeps executing interminably, so I thought that ...
3
votes
3answers
115 views

Why are packed structures not part of the C language?

Every C compiler offers the option to "pack" C structures (e.g. __attribute__ ((__packed__)), or #pragma pack()). Now, we all know that packing is required, if we'd like to send or store data in a ...
-4
votes
1answer
133 views

Calculate Pi to N number of places [closed]

I am trying to work out how to calculate Pi to N decimal places, I think the default DP's for a float/double is 5 and then you have setprecision() however these are obviously inadequate, I need ...
2
votes
1answer
144 views

How to store satellite data in C data structutres

I've been reading through Introduction To Algorithms 3rd Ed, and am really enjoying the material; however, I am having difficulty in implementing some practical situations. It's not the theory, or ...
1
vote
3answers
87 views

Reconstructing a huffman tree using minimal information in the header

I'm writing a huffman encoding program in C. I'm trying to include the least amount of information in the header as possible, I know the simplest way to decompress the file in the header would be to ...
2
votes
3answers
199 views

C/C++: Which conversion warnings make sense in practice?

C/C++ implicit conversions can cause bugs. Here's one example: int foo, bar; scanf("%d", &foo); scanf("%d", &bar); float foobar = foo / bar; If I input 7 and 2, it's not 3.5 as expected - ...
6
votes
2answers
357 views

C programming practice, passing a pointer to a function [closed]

Consider the following C function which takes as argument a string, which is then stored inside a struct: struct mystruct* usestring(char* string) { struct mystruct *struct; struct = ...
1
vote
2answers
130 views

Implementing a simple controller in embedded C

Is there a known method or pattern to implement a simple controller for an MVC design in pure C or the switch case approach is the standard? Background : I have an embedded application and I'm ...