Click here to Skip to main content
15,889,362 members
Everything / Programming Languages / C

C

C

Great Reads

by Martin Mitáš
How to support scrolling within your controls.
by Espen Harlinn
Choosing the right synchronization mechanisms when working with threads, thread-pools, and I/O Completion ports to create high performance asynchronous servers in C++
by Andy Allinger
Add features to k-means for missing data, mixed data, and choosing the number of clusters
by Jeffrey Walton
Perform authenticated encryption with Crypto++.

Latest Articles

by Chris Boss
BASIC: A powerful language often underestimated and undervalued
by ColleagueRiley
A multi-platform single-header very simple-to-use framework library for creating GUI Libraries or simple GUI programs.
by FPGANinja
A walkthrough and source code for designing a stream interface in Vitis HLS
by Alexey Shtykov
The thing that could generate pseudo random numbers faster than standard library does

All Articles

Sort by Title

C 

13 Mar 2015 by Member 11524225
#include #include #include #define M 100#define FLUSH while(getchar() != '\n')typedef struct node *nd;typedef struct { char bkNumber[5]; char bkTitle[M]; char bkAuthor[M]; int bkCopyright; ...
15 Mar 2015 by Frankie-C
All your code refers to a variable type nd defined as:typedef struct node *nd;In this case nd defines a pointer to an 'incomplete' node structure.The structure 'node' is defined nowhere, so when you want access fields of the structure the compiler doesn't know how to get them (the...
21 Feb 2013 by kavinsp
Hi , i am writing a web socket server implementation in c++, but i am getting this error "Error during WebSocket Handshake: Sec-WebSocket-Accept Mismatch" in console.Do you have any idea of what goes wrong for getting this error??RegardsKavin
14 Jan 2016 by Dishank Bansal
#includeint main(){float x = 9.81 ; if( x == 9.81){printf("the value of x is 9.81\n");}else {printf("No its not 9.81 \n");}}In this we expect "if" statement to execute but instead "else" statement get executed.Why is it so??
14 Jan 2016 by KarstenK
it is common issue that float arent exactly what they seem. ;-)The reason is there internal representation in the memory. Make an output of it.The solution is to calculate the difference an accept a small one. Remember that it maybe signed.float x = 9.81f; float d = x -...
14 Jan 2016 by CPallini
KarstenK already gave you the solution. I suggest you to read: "What Every Computer Scientist Should Know About Floating-Point Arithmetic"[^].
14 Jan 2016 by Sergey Alexandrovich Kryukov
Just my 5 cents in addition to other answers:It's not a good idea to use the operator == with floating-point operands. That's right, I don't know the situations where it can be useful at all. Even with floating-point values representing numbers with zero fractional part, you should not use...
21 Jan 2013 by zqliu
f1(), f2(), f3() is a function of type bool, which of the following style is better? A. if (f1 () && f2 () && f3 ()) do (); B. if (f1 ()) if (f2 ()) if (f3 ()) do ();If three function execution time is longer, is B method is better? Or they are just the same...
21 Jan 2013 by PIEBALDconsult
They should be about the same. I prefer A; it's more polished. Any fool can do B.
21 Jan 2013 by nv3
It actually doesn't matter from a run-time point of view. In other words, A and B will run equally fast. For readability purposes, however, I would always prefer A. or better yetif (f1() && f2() && f3()) doSomething ();
21 Jan 2013 by Abhinav S
I'd prefer A. If (f1 () && f2 () && f3 ()) do (); because it is much more clearer and easier to understand.You are using && which is a short circuit operator.If the first condition fails the second won't execute so there will be no difference in execution time in either case.
21 Jan 2013 by Andreas Gieriet
You left out a 3rd variant:bool hasSomethingToDo = f1() && f2() && f3();if (hasSomethingToDo){ DoSomething();}and a 4th variant:bool hasSomethingToDo = f1() && f2() && f3();if (hasSomethingToDo){ DoSomething();}Usually,...
21 Jan 2013 by H.Brydon
Any C/C++ compiler nowadays will treat both the same way and generate either the same code or almost the same code.A point perhaps more important than performance for this one-liner is maintainability. In most cases, 'A' is the better choice - if the logical tests are truly function names or...
28 Dec 2016 by Member 12919791
I'm trying to sort an array using the bubblesort method. I get the below "link error", which isn't clear. I can't use gdb/valgrind.~/workspace/pset3/find/ $ make helpers clang -fsanitize=integer -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wshadow...
28 Dec 2016 by Patrice T
May be the linker complain that there is no main function.
18 Jan 2017 by Member 12955853
So, i'm trying to make a program, that allocates enough space for 5 integers using malloc and a pointer to act as the array, and through a function, i'm doubling the size of the "array" using realloc, inserting the square of every number of the first 5, into the 5 next spaces. It's hard to...
17 Jan 2017 by Richard MacCutchan
You forgot to return the updated pointer from the double_old function. The code should be: old = double_old(old, old_size, new_size); free(old); }int * double_old(int *old, int old_size, int new_size){ int i=5, a=0; new_size = old_size*3; // why times...
17 Jan 2017 by Patrice T
When you allocate, it is 5 integersold=(int*) malloc(old_size*sizeof(int));When you reallocate, it is 15 bytes, no matter what is the size of an integer.new_size = old_size*3;old = realloc(old, new_size);
18 Jan 2017 by CPallini
Don't mess with old_size. Try#include #include int * double_old(int *old, int old_size);int main(void){ int *old; const int old_size = 5; int i; old=(int*) malloc(old_size*sizeof(int)); printf("Enter 5 integers: \n\n\n"); for(i = 0; i
18 Jan 2017 by nv3
Richard has already pointed out the bug in your program. There is nothing to add to that.As you are new to programming you should try to pick up the right habits from the very beginning. Therefore, I want to point out a couple of things to you could do better in this small example and which...
10 Aug 2015 by Member 11898126
Hello everyone!! I am an iOS client and trying to connect to the remote server with my self signed certificate. I add it to the keychain and start socket connection. When I try my code with localhost, I see some encrypted messages, but when I try to connect to the remote server I get the error...
5 Oct 2014 by KarstenK
Some toughts whether to prefer Objective-C or Swift.
3 May 2010 by Poonamol
Hi,I had written a C file which run on unix(AIX) system.In my C file, I used traces for errors.But when I run it, I am receiving warning messages "Trace is off".Can anyone tell me How to ON the traces in Unix.Help me out.Thanks in advance.
4 May 2010 by Richard MacCutchan
Use Google and search for "aix trace", or use the AIX help system.
26 Oct 2012 by steven8Gerrard
What does representation in 0*0x100u mean in C . If it end with "b" . I know its binary . What is "u"
26 Oct 2012 by BobJanova
U means unsigned, there's a full set here[^].
26 Oct 2012 by psychic6000
u is for unsigned, btw if you are multiplying it by 0 then it doesnt matter...
24 Apr 2017 by OriginalGriff
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action. Try it yourself, you may find it is...
24 Apr 2017 by Patrice T
Quote: iwanna solve this question as fast as you can Then start to work, we are not a code on request service; If you are in hurry, try paying services. We do not do your HomeWork. HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and...
1 Nov 2011 by Mehdi Gholam
Try the forum on : http://ioquake3.org/[^]They can probably help you better.
3 May 2019 by coffeenet
Hi,I am trying to compile ioauek3 on our IBM PowerPC machine that is running with a Linux environment.I got this error:#error You now need to define either FIXED_POINT or FLOATING_POINTI found that many say the fix is:make speex-reconfI...
24 Oct 2017 by Member 13483115
I have tried a lot but I didn't get solved will you help me out with this thank you...!! #include int main() { int a=(1, 2, 3); int b=(3, 2, 1); for(; a>0; a--) for(; b
24 Oct 2017 by Chris Losinger
Look into C's comma operator. When you know how that works, you will know what a and b will be initialized to.
24 Oct 2017 by OriginalGriff
The Comma operator looks like this: x = a, b; It evaluates the expression a, discards the result, evaluates b and returns it. So the code for a and b both get executed, and x is set to the value of b. Your code is just an extension of that: effectively x = ((a, b) , c); So it evaluates a and...
14 Mar 2013 by Bartlomiej Filipek
Include Guards, Pragma Once, Predeclarations and other hints that might be useful when dealing with includes.
2 Jun 2018 by Member 13856095
For manual calculation getting 64 but in turbo C complier getting 70 and in Java 64 how it varies can anyone explain What I have tried: If taking x=10 by doing the manual calculation getting the answer 64 but in complier getting 70 how is it possible
2 Jun 2018 by OriginalGriff
Simple: Why does x = ++x + x++ give me the wrong answer?[^] BTW: in future, don't put your code as the subject line - that's what "What I have tried" is there for. The subject line should be short and sweet, and quick overview of the problem in English as much as possible. Perhaps "x++ giving...
2 Jun 2018 by Patrice T
You are in gray zone: the code is legal, but unpredictable. y=x++ + ++x + ++x + ++x + ++x; The compiler is free to reorder what is in this code. for x=10, y can be anywhere between 50 and 75. The only advice is: never mess with multiple increment/decrement operations in a single line of code.
24 Jun 2011 by Albert Holguin
%zu is not a valid modifier for printf()(the z is not a modifier at all):http://www.cplusplus.com/reference/clibrary/cstdio/printf/[^]use this instead and it should work just fine:printf ("The chapters array uses %u bytes of memory.\n", sizeof(chapters));
24 Jun 2011 by Member 641034
The %zu marker should return value when You use sizeof() function. In a console application there is a message "The chapters array uses zu bytes of memory." It should return number of bytes used by these two stings, not this "zu".#include #include #include...
12 Sep 2022 by Everything Select
In my laptop, I've tried to use the beep escape sequence (i.e. '\a'), it worked fie in codeblocks, but it isn't working at all in vs code even with the same code as what I wrote in codeblocks. I've seen c tutorials in c, so I do know that vs code...
12 Sep 2022 by Dave Kreskowiak
Works fine for me, though if you're expecting a beep out of the internal PC speaker, that's not where the sound comes from. Today, a "beep" would be whatever sound is configured in the Windows Sound control panel and come out of the sound...
12 Sep 2022 by k5054
printf() may not flush the output buffer until a newline ('\n') is seen, or the output buffer is full. Try adding fflush(stdout); after each printf(), to force the buffer to be flushed.
26 May 2015 by Member 3612029
I have installed Borland 5.5 C++ in my machine.I have installed it in C:It's path is like this. C:\BorlandAlso I have set this path information in the System PATH variable as like this. C:\Borland\BCC55\BinAfter setting this path I am able to call bcc32.exe from the command prompt and...
27 May 2015 by Jochen Arndt
The error shows:Quote:'brcc' is not recognized as an internal or external commandSo it seems you are using 'brcc' instead of 'brcc32' somewhere in your make file.
25 Jun 2013 by SanjeevJayaram
While inserting and updating the sqlite database table it works for the first time correctly. while running it for second time error comes as 'database is locked'.what is wrong in it.
26 Oct 2021 by Jahirul Sarker
[Updated] I was trying to solve this problem: 1098 - Sequence IJ 4 - URI Online Judge[^] I used else if statement to print integer when needed. It worked for two conditions but it's not working for the third condition. The code I wrote is given...
20 Oct 2021 by Rick York
What is happening is you are bumping up against small, numerical errors in floating point values. The value of i after ten 0.2s were added will not match 2.0 exactly. It probably will out to be about eight or nine decimal places but not...
23 Oct 2021 by Patrice T
Quote: I used else if statement to print integer when needed. It worked for two conditions but it's not working for the third condition. The code I wrote is given below. Because your code says so: #include int main(){ int a,b,c,d,e,...
26 Oct 2021 by Jahirul Sarker
Here's the solution: #include int main(){ double i,j; for(i=0; i0.9&&i
14 Sep 2010 by Ohmu
An article that creates a simple iPhone application that displays a graphic then cuts out the .XIB, and completes this just from the code.
11 Oct 2018 by Member 14016042
I want to create a program that receives a number N as an argument and starts N threads each displaying one of the numbers from 1 to N synchronously, to produce an ordered sequence (12 ... N) *. Where, it is necessary to use one and the same function executed by all threads and pass the number...
11 Oct 2018 by OriginalGriff
mutex is declared as part of your main function: int main(int argc, char *argv[]) { N = atoi(argv[1]); sem_t mutex[N]; which makes it a local variable - its scope is limited to the set of curly brackets which most recently enclose it - the main function itself. And then you try to...
12 Oct 2018 by KarstenK
Really strange that the first error is at this line. The compiler should complain already on: sem_t mutex[N]; This code shuld do the job sem_t *mutex = malloc( sizeof( sem_t ) * N ); //at the ende free( mutex ); Tip: set the warning level higher. This warnings are helping you to write good code :-)
11 Oct 2018 by Member 14016042
Sorry I copied the wrong code. #include #include #include #include #include //#include // pour les threads #include // pour les semaphores #include // pour les flags O_CREAT, O_EXCL, ... //...
11 Oct 2018 by CHill60
If the code you have posted as a solution is genuinely the code causing the error then try changing sem_wait(& mutex[N-1]); to sem_wait(&mutex[N-1]);
27 May 2015 by Member 3612029
Hi All,I have a make file, where it generates .Obj files and .res files successfully. After generating these files, there is command called as "@sscheck abc.dll".I am using Borland 5.5 compiler and have installed it in C:\. I have checked the Bin folder, but there is no such command as...
27 May 2015 by CPallini
This page might interest you: "What is the output of SSCheck.Value in VB6?"[^].
12 Jan 2021 by honotard
Pretty new to programming, been doing some pretty basic stuff but I came across a more complicated one now, not sure how to start with it. Task: Given a positive integer N, what is the minimum positive integer K such that K! is a multiple of the...
12 Jan 2021 by CPallini
[update] The 'Output' looks wrong to me. Look, for instance, at the last input item, namely 24. The output reports 48 as solution. However, (9!)/(24^2) = 630 so 9 looks a better fit to me. Incidentally, considering the details of such a case...
9 Jan 2021 by OriginalGriff
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us...
12 Jan 2021 by Patrice T
Quote: Nothing so far. Having problems with implementing the whole thing cuz I'm truly not sure how to do it. You need to understand the problem and its solving. First step, train yourself solving the problem by hand with some small N. When...
12 Jan 2021 by Luc Pattyn
This is a mathematical problem as well as a programming problem. You need to understand the maths involved and come up with a sensible approach before even attempting to program anything. And then you must keep in mind that K! is growing rapidly...
28 Feb 2021 by Member 15086508
Hey all noob programmer here. I thought Instead of watching tutorials just to jump In and build stuff and learn on the go and trial and error rather than just being stuck In tutorial limbo. First Is obvious a basic hello world Program easy done....
28 Feb 2021 by OriginalGriff
Because the C language is case sensitive: "I" is not the same as "i" Change this line:Int main(){ To this:int main(){ And in future, don't take photos of your screen and post links to them: copy'n'paste the actual text and post that here,...
25 Oct 2023 by Member 16116753
I don't know If I can ask about C language, sorry if I can't. I tried to understand these two codes: int *pv = (int*) malloc(5 * sizeof(int)); for(int i=0; i
16 Oct 2023 by OriginalGriff
Of course you can ask about C - just because it is a fifty year old language and shows it's age badly doesn't mean you can't ask about it! If you are learning it as your first language though, it's going to be of little help in getting you a job...
16 Oct 2023 by CPallini
malloc (see, for instance: malloc - cppreference.com[^]) allocates on the heap, while, in the 'simpler example', the array is allocated on the stack. If you need a bidimensional dynamically allocated array (specifically a jagged array[^]) then...
16 Oct 2023 by Maxim Kartavenkov
This is the generic understanding of the pointers itself. The pointer means that it contains an address of the memory. In you example you have an array: int x[5] = {1, 2, 3, 4, 5}; So the x is the pointer to the array in memory with the 5 integer...
16 Oct 2023 by KarstenK
malloc only allocated some memory block and it is your task to deal with that memory and use some typed pointer to work with it. For complex solution I recommend the usage of structs which give you (and the compiler) some help how to deal with...
14 Jan 2021 by honotard
Been doing a task in C programming language. I had a problem with fmod which gave me a specific error after trying to execute and give permission.(Undefined reference to fmod, error ld returned 1 exit status). Some people helped me on this...
14 Jan 2021 by Afzaal Ahmad Zeeshan
From a high-level overview, the code looks nice, secondly the code "compiles" just fine too: C++ Shell[^]. What I feel like is there might be an invalid character (most likely an invisible one) that is causing trouble for the compiler. Oh, and...
14 Jan 2021 by OriginalGriff
I just tried it using gcc via rextester, and your code shows no such error: Compilation time: 0.12 sec, absolute service time: 0,29 sec Error(s): 1693378824/source.c: In function ‘main’: 1693378824/source.c:12:1: warning: ignoring return value of...
14 Jan 2021 by CPallini
Your code compiles fine (as already noted by our Griff). Just link it with the math library in order to obtain the executable, e.g. gcc -Wall foo.c -lm Please note, factorial results become 'unmanageable' very fast: even 64 bit integers can...
4 Nov 2019 by Member 14643779
This is a mini c project I working right now. I try to login after I register a new account,but even I input the correct information still fail to login, can't find the error. The code is quite a lots, but I tried my best to minimize. Code: This is the main interface when the console run, for...
3 Nov 2019 by OriginalGriff
Compiling does not mean your code is right! :laugh: Think of the development process as writing an email: compiling successfully means that you wrote the email in the right language - English, rather than German for example - not that the email contained the message you wanted to send. So now...
4 Nov 2019 by Richard MacCutchan
I would suggest you start again. Your code seems to be far too complex for such a simple system, and there are one or two things that are a waste of time. Start with a system that just takes a userid and a password, so you can minimise the amount of code that needs to be tested. For a...
7 Apr 2014 by Bhatt Aniruddh
hi all,i have two list boxes. i want contact synchronization folder and email synchronization folder in list boexs.i tried following code...private void EnumerateFoldersInDefaultStore(){ Outlook.Folder root = Application.Session.DefaultStore.GetRootFolder() as...
4 Aug 2013 by z3ngew
Hello everyone,I made the following function, which i use to drive stepper motorint16 position2steps(double position){ int16 steps = 0; if(!strcmp("HALF", step_mode)) steps = (position / half_angle); else steps = (position / step_angle); return...
5 Aug 2013 by User 59241
Quote:but if i use this function frequently it give 1 for some time but then it return 0 This is a very strange comment because it should always return the same output for the same input.Nevertheless not all numbers can be exactly represented as a double. This means you end up with...
5 Aug 2013 by Jochen Arndt
If you want to round to the nearest integer, add a value of 0.5 to the result before converting to an integer. If you want to round down, add a small value (e.g. 0.01 in your case).The problem is that most rational numbers can't be represented exactly using floating point numbers. If you...
5 Aug 2013 by pasztorpisti
Floating point numbers can not accurately represent every real numbers, just a few of them. If you say for example d=1.333 then d will contain a floating point value that is near to 1.333 but isn't exactly 1.333 because it can not be accurately represented. The same is true to 0.1 and 0.9 and...
5 Aug 2013 by Philippe Mori
In such case, I think you should round number before converting them to integer.In many cases, it might not matters much. You have taken an example where you are really near a "split" point. In practice, if you round every thing, then instead of having the problem for number that are a whole...
23 May 2012 by Sergeant Kolja
This is an alternative for "Memory leak detection for WinCE".
20 Oct 2010 by zhisen
The following program i done are only able to detect half of the edge , can anyone solve this problem for me please ? thanks #include #include #include void main(void){FILE *fptr1, *fptr2;int row, col, r, c, i, j, max_gray;int threshold;int...
18 Jan 2015 by KeketZee
I'm doing this in ***Visual Studios: Visual C++/win32/Win32 Console Application*** I'm aware that it looks more like C. I tried using the variables in my C++ book, But the program didn't read them. Is there a different #Include I should be using so it works? What should I be using instead of...
18 Jan 2015 by CPallini
If you really want to use C-like code then you have to use character arrays for player names. And you have to always check the return value of scanf.Using std::string together with std::cin, std::cout for I/O would greatly help you.Moreover I would use a struct (or a class) for holding...
18 Jan 2015 by OriginalGriff
It's difficult to explain exactly what you are doing wrong without being able to see when your eyes start to glaze over...You are declaring your player names as charchar p1;char p2;char p3;but then you use them as a string: //Asks for Player Names printf("Player 1, Please...
4 Aug 2013 by xXTariqoO
Hello,i started to learn about driver programmingi want to make my driver do a thing every 2000 ms for exampleand in c++ i will be like thiswhile(true){Sleep(2000);//(2 Seconds)DoSomething();}the question is :how to do like it in c driverit must be like...
4 Aug 2013 by User 59241
The principle is exactly the same as creating delays in user mode. Sleep() has very limited value and you can use Google to find out why. Ultimately you need waitable timers.(1) Create a kernel timer via...
25 May 2014 by zaki al
Also you can use KeDelayExcutionThreadThird parameter of this function is in 100 nano seconds(0.01 micro seconds)http://msdn.microsoft.com/en-us/library/windows/hardware/ff551986%28v=vs.85%29.aspx[^]
15 Jul 2010 by vikasvds
Hi all,A diamond made of * given below can be easily printed on the screen using some loops. * *** ***** ******* ***** *** *But i have got a question from one of my friend says print the same * diamond using only one loop.I have tried with many ways such as...
15 Jul 2010 by Dalek Dave
What code have you written already?On seeing that I can probably point you in the right direction quite quickly.
15 Jul 2010 by Andrew Rissing
You could technically print it without any loops what so ever. You think about what you're doing with two loops and reorganize the logic without the inner loop.Sorry, I cannot give you more based on the lack of code and the chance that this is really just homework in disguise.
16 Jul 2010 by Aescleal
Just print it on the screen using one write to the console - it's only hello_world in disguise. The only time you'll need a loop is if you're doing something that changes every run of the program and is set up by the program's users.Cheers,AshPS: As other people have already pointed...
15 Jul 2010 by vikasvds
Hi all,Sorry to not to paste code written by me.I am almost able to get it with one loops but i am not liking too many variables and if-else.i am unable to think of any single straight logic/equation to do the sameit is below here -#define ROWS 10int main(void){ int i =...
15 Jul 2010 by Sauro Viti
You can work around the code snippet below:char szSpaces[] = " ";char szStars[] = "*****************************************";int iSpaces = 5;int iStars = 7;printf("%.*s%.*s\n", iSpaces, szSpaces, iStars, szStars);Such a format string instruct the printf...
16 Jul 2010 by Sauro Viti
Try this:#include #include const char szSpaces[] = " ";const char szStars[] = "********************************************************************************";int main(int argc, char* argv[]){ if (argc != 2) return...
12 Oct 2010 by Swapnil_katre
I have Declared all my declaration in one file called ADeclaration.h and included this file in all my module C files.i.e.I have MAIN.c (MAIN) Port_IO.c (PORT_IO) STORAGE.c (STORAGE) TEMPERATURE.c (TEMPERATURE) CONVERT.c (CONVERT) UART.c (UART) RTC.c (RTC) I2C.c (I2C)...
12 Oct 2010 by E.F. Nijboer
Simply put this in your ADeclaration.h to avoid multiple inclusions:#ifndef ADECLARATION_H#define ADECLARATION_H // Contents of ADeclaration.h #endifGood luck!