- Strength to Increase Rep
- +3
- Strength to Decrease Rep
- -0
- Upvotes Received
- 5
- Posts with Upvotes
- 5
- Upvoting Members
- 5
- Downvotes Received
- 2
- Posts with Downvotes
- 2
- Downvoting Members
- 2
Re: [QUOTE=ohyeah;659404]It's part of the C89 and C99 standard to require a newline at the end a non-empty file so any C compiler that does not warn about it is not following the standard.[/QUOTE] Yes, you are right. According to 5.1.1.2.2 "A source file that is not empty shall end in … | |
Re: [QUOTE=bops;655242]Ok, thanks a lot. Actually, can you use sprintf like this, and is it safe? [code=c] int len; len = sprintf(NULL,"This is my forename: %s",fname); [/code] And then use len to allocate the memory for msg?[/QUOTE] No at all. Right way is to use strlen, and then dynamically allocate buffer … | |
Re: [QUOTE=shankhs;658734]Hi guys! I have started learning geometry and wrote a code to calculate the distance between a line(or a segment) and a point. [/QUOTE] Rewrite your distance function like this: [CODE=C] double distance(int a[],int b[]) { double d1=b[0]-a[0]; double d2=b[1]-a[1]; return sqrt(d1*d1+d2*d2); } [/CODE] General rule -- if you do … | |
Re: The simplest way is to use Newton method: [CODE=C] #define TOLERANCE 0.0001 double myabs(const double x){ if (x > 0.0) return x; return -x; } double mysqrt(const double x){ double assumption = 1.0; if (x < 0.0) return 0.0; while (myabs(assumption * assumption - x) > TOLERANCE){ assumption = 0.5 … | |
Re: [QUOTE=kux;658561]I've been searching for a memory leak detection tool for windows, something similar to valgrind under Linux, but all tools that i find cost, or just have free trials. Does anyone know a FREE memory leak detection tool for windows ?[/QUOTE] Check this: [url]http://www.codeproject.com/KB/applications/visualleakdetector.aspx[/url] It is free with full source … | |
Re: [QUOTE=Nemoticchigga;658737]I am running a thread that does something, then sleeps for a while. If the program closes it continues to sleep to completion. How do I get it to abort immediatly, even if in the middle of sleeping?[/QUOTE] You may use TerminateThread function, it will terminate your thread immediatly, but … | |
Re: [QUOTE=robertmacedonia;658571]Hi, I would like to ask you for help in converting this code from C to C++. [/QUOTE] Code, that you posted is correct C++ code, except nonstandard main declaration. But to be "just more C++", you may rewrite it as follows: [CODE=C++] #include <string> #include <iostream> int main(void) { … | |
Re: [QUOTE=tzushky;657916]Hello, [CODE=C] typedef struct FIFO_TAG{ struct FIFO_TAG *NextElement; }FIFO; [/CODE] And then FIFO would be used. [/QUOTE] That example is rather useless without any data fields in FIFO_TAG, but may be you've dropped ones for clarity. First of all, FIFO is simply an alias, so the declaration may be rewritten … | |
Re: You using qsort to sort "strings of 10 chars", aren't you? So tou ought to pass to qsort proper size -- i.e. 10*sizeof(char). Also you wrote str_cmp rather unusual, I corrected it to be more simple. Try this one, it works: [CODE=C] #include<stdio.h> #include<stdlib.h> #include<string.h> int str_cmp(const void *prv,const void … | |
Re: [QUOTE=kzdev;647922]I want to make a function to pass and return values from the same arguments. For example prm3=0 after function's execution must become prm3=3, and next prm3=6, and next prm3=9 ...[/QUOTE] You are passing parameters by value. Pass pointers instead. [CODE=C] #include <stdio.h> void increments (int* p1, int* p2, int* … |