Forum: C 3 Days Ago |
| Replies: 14 Views: 327 Bleh. I need to call it a night and leave better advice to others.
#include <stdio.h>
#include <string.h>
#define NAME_LEN 25
#define OWNER_LEN 25
#define STATUS_LEN 4
#define DATE_LEN 11... |
Forum: C 4 Days Ago |
| Replies: 7 Views: 201 Dunno.
#include <stdio.h>
#include <stdlib.h>
/**
* A simple line-counter. (Has issues with special cases.)
* @param file pointer to a file stream
* @return the number of lines in the... |
Forum: C 12 Days Ago |
| Replies: 7 Views: 350 Try printing the bytes in the buffer rather than printing the buffer as a string (especially when you are not treating buffer as a string). |
Forum: C 13 Days Ago |
| Replies: 1 Views: 199 Expected input and output would be helpful. Providing a small snippet of a simple test, minimal but complete and compilable, would too.
"This code doesn't do what I want (and I'm not going to tell... |
Forum: C 14 Days Ago |
| Replies: 14 Views: 658 *sigh*
Of course it is. ALL structures of the structures in the first example are populated at compile time. A particular one isn't "selected" in the if tree. |
Forum: C 30 Days Ago |
| Replies: 2 Views: 266 fmod (http://web.archive.org/web/20050207005628/http://dev.unicals.com/papers/c89-draft.html#4.5.6.4) |
Forum: C Oct 26th, 2009 |
| Replies: 2 Views: 197 Do you really think this is enough information for any kind of an answer? |
Forum: C Oct 25th, 2009 |
| Replies: 6 Views: 205 http://c-faq.com/stdio/scanfhang.html |
Forum: C Oct 19th, 2009 |
| Replies: 6 Views: 270 Go back and look at that link I'd posted, I'm sure it mentions code tags at some point.
Do you know which language you are using? You seem to have merrily mixed C and C++ (perhaps "borrowing" code... |
Forum: C Oct 4th, 2009 |
| Replies: 8 Views: 65,583 Why not post this failing example so I know what you mean?
Brought up recently by tux4life and explained by Narue (http://www.daniweb.com/forums/post956935.html#post956935), the fgets/sscanf code... |
Forum: C Oct 1st, 2009 |
| Replies: 5 Views: 514 Danke. I was thinking something a little more canned:
#include <stdio.h>
#include <limits.h>
/* Check if s1 and s2 are anagrams of each other */
int isAnagram(const char *s1, const char *s2)
{... |
Forum: C Sep 30th, 2009 |
| Replies: 11 Views: 634 %d -> %02d
#include <stdio.h>
int main(void)
{
int h = 1, m = 1, s = 1;
printf("%02d:%02d:%02d", h, m, s);
return 0;
} |
Forum: C Sep 26th, 2009 |
| Replies: 26 Views: 986 I'll sidestep the why for a moment and mention that strlen is a reserved identifier and simply should not be used for your own function name.
[edit]C Reserved Identifiers... |
Forum: C Sep 21st, 2009 |
| Replies: 17 Views: 1,464 #include <stdio.h>
#include <limits.h>
int main()
{
int x;
unsigned y;
printf("INT_MAX = %d\n", INT_MAX);
if ( 0xFFFF < INT_MAX ) |
Forum: C Sep 17th, 2009 |
| Replies: 2 Views: 408 remove is the name of a standard library function, choose another name. |
Forum: C Sep 7th, 2009 |
| Replies: 9 Views: 412 FWIW: http://www.daniweb.com/forums/thread49488.html |
Forum: C Aug 27th, 2009 |
| Replies: 8 Views: 394 I'd say your understanding of char *a needs a little work.
I would say that a is a pointer that points to an unnamed array of constant characters.
Maybe these will help:... |
Forum: C Aug 19th, 2009 |
| Replies: 15 Views: 492 Danger Will Robinson! That's not a compiler, it's an unfinished toy.
I'd recommend finding a different compiler, yes. |
Forum: C Aug 17th, 2009 |
| Replies: 1 Views: 222 Seems more like C++. Do you have a minimal compileable snippet that produces the results you see?
#include <stdio.h>
struct f_c_8
{
union
{
float f;
unsigned char c[8];
... |
Forum: C Aug 12th, 2009 |
| Replies: 22 Views: 1,076 Read the user input as a string, validate the string according to the specific details for dollar amount entry. Such as, begins with dollar sign, is followed by nothing but digits until a possible... |
Forum: C Aug 7th, 2009 |
| Replies: 12 Views: 725 No.
Try to think about the real loop control and a better loop construct will come to mind.
---
http://en.wikipedia.org/wiki/Goto#Criticism_of_goto_usage |
Forum: C Aug 2nd, 2009 |
| Replies: 18 Views: 1,107 As you saw in the link...
The standard behavior is to do nothing in particular for any keypress, save the return key. |
Forum: C Jul 31st, 2009 |
| Replies: 16 Views: 757 So loop.
double *powerArgs(int *a, int *b)
{
static double result;
int i;
for ( i = 0, result = 1; i < *b; ++i )
{
result *= *a;
}
return &result; |
Forum: C Jul 30th, 2009 |
| Replies: 16 Views: 757 pow (http://web.archive.org/web/20050207005628/http://dev.unicals.com/papers/c89-draft.html#4.5.5.1)? |
Forum: C Jul 29th, 2009 |
| Replies: 5 Views: 227 A brief note on signals and calling standard library functions:
http://groups.google.com/group/comp.lang.c/browse_thread/thread/00d5082d648b2437/a4d67511412817da#a4d67511412817da
[edit]Doing some... |
Forum: C Jul 26th, 2009 |
| Replies: 7 Views: 240 http://c-faq.com/expr/ieqiplusplus.html |
Forum: C Jul 9th, 2009 |
| Replies: 11 Views: 503 I don't know if I read you correctly. My hint towards a suggested replacement would be:
char **arrayToReturn = malloc(height * sizeof *arrayToReturn);[edit]This being your original:
char**... |
Forum: C Jul 8th, 2009 |
| Replies: 6 Views: 343 #include <stdio.h>
int main(void)
{
int b[10][5] ;
int (*q)[10][5] = &b ;
printf("%p - %p = %d chars\n", q+1, q, (char*)(q+1) - (char*)q);
printf("%p - %p = %d ints\n", q+1, q,... |
Forum: C Jun 19th, 2009 |
| Replies: 24 Views: 1,430 man difftime (http://clusty.com/search?query=man%20difftime)
[edit]This (http://www.daniweb.com/code/snippet367.html) has similarities to the original topic.
Slight nitpick:
A time_t is not... |
Forum: C Jun 16th, 2009 |
| Replies: 16 Views: 1,092 They are the same for printf, but they are different for scanf. Both are used for integers, though. %i may read the input as hexadecimal or octal as well as decimal. |
Forum: C Jun 5th, 2009 |
| Replies: 1 Views: 566 http://c-faq.com/stdio/scanfhang.html... |
Forum: C Jun 2nd, 2009 |
| Replies: 22 Views: 931 |
Forum: C Jun 2nd, 2009 |
| Replies: 22 Views: 931 #include <stdio.h>
void showcolor(int color)
{
if ( color && 1 ) puts("violet");
if ( color && 2 ) puts("indigo");
if ( color && 4 ) puts("blue");
if ( color && 8 )... |
Forum: C May 28th, 2009 |
| Replies: 23 Views: 937 http://projecteuler.net/index.php?section=problems |
Forum: C May 22nd, 2009 |
| Replies: 15 Views: 1,176 sscanf (http://www.daniweb.com/code/snippet353.html) or strtoul (http://www.daniweb.com/code/snippet441.html)?
#include <stdio.h>
int main()
{
const char representation[] = "1234";
int... |
Forum: C May 20th, 2009 |
| Replies: 18 Views: 813 Writing to read-only memory is undefined behavior. Maybe take another swing at this one. |
Forum: C May 15th, 2009 |
| Replies: 5 Views: 554 It is often prudent to test around the edges.
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int cmp1(int a, int b)
{
return a == b ? 0 : a < b ? -1 : 1;
} |
Forum: C May 7th, 2009 |
| Replies: 9 Views: 370 NULL, 0, \0 and nul (http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1047589067&id=1043284376) |
Forum: C Apr 20th, 2009 |
| Replies: 18 Views: 805 Sometimes I choose sscanf. Ballpark?
#include <stdio.h>
#include <ctype.h>
void parse_title(const char *text)
{
char word[128];
/* skip leading whitespace, if any */
while (... |
Forum: C Oct 10th, 2008 |
| Replies: 7 Views: 764 Consider also sscanf for parsing the source string.
#include <stdio.h>
int main()
{
const char text[] = "7/23/76";
int month, day, year;
if ( sscanf(text, "%d/%d/%d", &month, &day,... |