Forum: C 12 Hours Ago |
| Replies: 4 Views: 101 I would definitely think about rewriting that ... thing ... using arrays.
But here:
double computation(matrix k, int mA, int nA, int matrix, int m1, int m2, int m3, int m4, int m5, int m6, int... |
Forum: C 16 Hours Ago |
| Replies: 16 Views: 171 I tend to avoid the double-strlen call myself. |
Forum: C 16 Hours Ago |
| Replies: 16 Views: 171 ch should be an int.
Prefer '0' to 48.
It doesn't handle negative values (or those beginning with +).
It has overflow issues.
I prefer C90 to C99 for more generic examples. |
Forum: C 16 Hours Ago |
| Replies: 16 Views: 171 You're getting input from fgets, right? If you don't exceed the buffer size, what will the last character be? Are you checking for it? Got any misplaced semicolons? Is that particular comparison even... |
Forum: C 17 Hours Ago |
| Replies: 16 Views: 171 I might like yours if you'd fix the errors. ;)
[edit]BTW/FYI, one in the links of the tutorial was to a snippet that uses strtol (http://www.daniweb.com/code/snippet216679.html) too. |
Forum: C 18 Hours Ago |
| Replies: 16 Views: 171 http://www.daniweb.com/tutorials/tutorial45806.html |
Forum: C 2 Days Ago |
| Replies: 2 Views: 120 When there are compiler errors, you get no .exe. You need to fix the errors before the program will be created; once an .exe is build you can run it.
You're trying to compare an int to a... |
Forum: C 2 Days Ago |
| Replies: 1 Views: 134 In another post (http://www.daniweb.com/forums/post1071291.html#post1071291) I found the following construct:
#define STATIC_ASSERT(condition) \
do \
char... |
Forum: C 2 Days Ago |
| Replies: 21 Views: 533 http://www.c-faq.com/stdio/scanfhang.html
http://www.c-faq.com/stdio/scanfinterlace.html
http://www.c-faq.com/stdio/scanfc.html
http://www.c-faq.com/stdio/scanfjam.html... |
Forum: C 3 Days Ago |
| Replies: 5 Views: 209 #include <stdio.h>
int main()
{
const char filename[] = "file.txt";
FILE *file = fopen(filename, "r");
if ( file )
{
char line[BUFSIZ], text[10];
while ( fgets(line,... |
Forum: C 3 Days Ago |
| Replies: 7 Views: 213 Are you sure you've got the correct formula (http://en.wikipedia.org/wiki/Body_mass_index)?
Checking the return value from scanf is a good idea.
#include <stdio.h>
int main(void)
{
float... |
Forum: C 4 Days Ago |
| Replies: 7 Views: 269 http://web.archive.org/web/20080618001558/c-faq.com/bool/bool2.html |
Forum: C 4 Days Ago |
| Replies: 6 Views: 255 That reminds me of an old post (http://www.daniweb.com/forums/post94143.html#post94143). But I seem to have left out recursion. :P
(And it looked better in the original colors.) |
Forum: C 4 Days Ago |
| Replies: 3 Views: 184 To change the value of an object in a called function, you generally pass a pointer to the object.
#include <stdio.h>
#include <stdlib.h>
void allocate_matrix(int ***table, int rows, int... |
Forum: C 4 Days Ago |
| Replies: 4 Views: 219 "They" didn't. It's for a third party library, one that was meant to work with DOS. Not a windows console, mind you, but DOS. Code that uses it is really meant for DOS. It doesn't really belong in... |
Forum: C 5 Days Ago |
| Replies: 1 Views: 197 One way:
#include <stdio.h>
int main()
{
const char filename[] = "file.txt";
FILE *file = fopen(filename, "r");
if ( file )
{
char crossword[10][10]; |
Forum: C 5 Days Ago |
| Replies: 2 Views: 213 Well, being new to both probably puts you in a spot. You could write your own parser if the XML file will always and forevermore be canned and simple, and that might be easiest.
But I might also... |
Forum: C 11 Days Ago |
| Replies: 14 Views: 484 Well, it matters to the parsing. Different formats require different things in the parse. As this exercise kinda shows. |
Forum: C 12 Days Ago |
| Replies: 14 Views: 484 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 12 Days Ago |
| Replies: 14 Views: 484 I've been off my game tonight and subpar with my attempts to help (as I mentioned in another thread as well.
I had muffed the input data for one thing. |
Forum: C 12 Days Ago |
| Replies: 14 Views: 484 I'm thinking the empty fields is not working well with strtok. As I've mentioned, I'm not a strtok fan. Are you required to use it? |
Forum: C 12 Days Ago |
| Replies: 14 Views: 484 Thanks for the whole code.
I'm generally not a "parsing with strtok" fan; handling empty fields I've done this way:
http://www.daniweb.com/code/snippet216569.html... |
Forum: C 12 Days Ago |
| Replies: 14 Views: 484 I really don't care to make up the #defines and the rest. Do you suppose you could just post a small, but complete and compilable snippet?
kthxbye
[edit]But the nested loops don't look like a... |
Forum: C 12 Days Ago |
| Replies: 7 Views: 350 In C++ you need to specifically cast it. In C, it's better to avoid the cast.
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1047673478&id=1043284351 |
Forum: C 12 Days Ago |
| Replies: 7 Views: 350 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 I may have been pokey with my edit -- you'll need to rewind fp before you start trying to read the data.
Having a safety check like this...
for ( i = 0; i < lines; i++ )
{
if (... |
Forum: C 12 Days Ago |
| Replies: 7 Views: 350 getc returns an int; EOF is an int.
[edit]Also, you'll need to rewind fp the way you're doing things..
int countlines(FILE* fp)
{
int c, lines = 0;
while ( (c = getc(fp)) != EOF )
{... |
Forum: C 17 Days Ago |
| Replies: 4 Views: 284 What kind of meaning do you expect for (2 * pRoot)? |
Forum: C 17 Days Ago |
| Replies: 4 Views: 284 The compiler warns because generally it isn't what someone wants. But multiplying by two is the same as adding self to self.
[edit]Heh. But that won't work with pointers. Probably also for good... |
Forum: C 20 Days Ago |
| Replies: 7 Views: 406 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 21 Days Ago |
| Replies: 5 Views: 260 Okay. That one too.
Is the thing on the left side of the-> operator a pointer? |
Forum: C 21 Days Ago |
| Replies: 5 Views: 260 |
Forum: C 21 Days Ago |
| Replies: 1 Views: 228 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 22 Days Ago |
| Replies: 5 Views: 388 Use system-specific APIs and write a fair amount of character-handling code.
Or use simple standard library functions and reject unwanted input.
Which is it that you want? |
Forum: C 22 Days Ago |
| Replies: 14 Views: 774 *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 22 Days Ago |
| Replies: 14 Views: 774 Your first example may not be working the way you think it is. The #include directive is like a copy-and-paste that happens at compile time. You can't do it at runtime. |
Forum: C 27 Days Ago |
| Replies: 2 Views: 309 http://c-faq.com/stdio/fupdate.html ? |
Forum: C 27 Days Ago |
| Replies: 3 Views: 337 Are any of the suggestions here usable?
http://c-faq.com/varargs/nargs.html |
Forum: C 30 Days Ago |
| Replies: 6 Views: 389 struct amicable* record;
/* allocate array of pointers */
record->amicablePair=(int**)malloc(nrows*sizeof(int*));record needs to point to something before you dereference what it points... |
Forum: C 30 Days Ago |
| Replies: 2 Views: 224 getline is not standard C. |