Forum: C 34 Days Ago |
| Replies: 2 Views: 245 Save the result of the string compare so you wont do it twice. Then just increment a counter.
int seq_Search(char array[][MAXSIZE], int end, char *key)
{
int mid;
int first = 0;
int... |
Forum: C Oct 31st, 2009 |
| Replies: 2 Views: 306 Insert at line 123 ...
else
{
printf("\nduplicate or unknown character\n");
}
and see what you get. |
Forum: C Oct 31st, 2009 |
| Replies: 1 Views: 184 Just cast the return, time_t is equivalent to int for 32 bit OS.
return (int) MTIME;
To fix the printf warning include stdio.h |
Forum: C Oct 31st, 2009 |
| Replies: 3 Views: 255 It works for both cases here.
I didn't see any glaring problems that relate to your issue.
At line 97 I think you intended something else ...
for(ctr = 0; ctr < strlen(n); ctr++)
sum +=... |
Forum: C Oct 29th, 2009 |
| Replies: 10 Views: 806 You should be able to see how by now.
What controls space output? The variable spaceNeeded. If true it will output a space before the next character.
Now where should it be set to true?
... |
Forum: C Oct 24th, 2009 |
| Replies: 3 Views: 289 Well it looks like that's what it's supposed to do.
It should print the hex representation of the floating point number 4.379.
But I don't see how it will compile and it will only print 3 of the... |
Forum: C Oct 23rd, 2009 |
| Replies: 10 Views: 806 This code is the same as you had. Just re-arranged a little.
I moved the sentence check first to catch the next non dot. The way it was (after the space skip) made it impossible to tell between the... |
Forum: C Oct 23rd, 2009 |
| Replies: 6 Views: 466 The first improvement I found was that you don't need to regenerate all the primes every time. Split the array into separate arrays. One global array of primes and one for factor counts.
This... |
Forum: C Oct 21st, 2009 |
| Replies: 10 Views: 806 Sorry for the double post, could not edit for some reason...
Another look, in order to catch the next non dot correctly you have to check before the skip space loop.
#define FALSE 0
#define... |
Forum: C Oct 21st, 2009 |
| Replies: 10 Views: 806 The last condition should not check for new line any more. You want to restart skipping after the last sentence now (when the count is reached as I said). In other words when you do putchar('\n');
... |
Forum: C Oct 20th, 2009 |
| Replies: 10 Views: 806 Just a few things to clear up.
1) How are existing new lines to be handled? If they should be ignored then line 35 should not output if c == EOL.
2) In the skip space loop you will skip new... |
Forum: C Oct 14th, 2009 |
| Replies: 14 Views: 493 Agreed. Saying it will crash is highly subjective.
I will try to avoid that in the future. I forget that what's 'obvious' to me is not to every one :) |
Forum: C Oct 14th, 2009 |
| Replies: 14 Views: 493 It's purely theoretical. You shouldn't have to compile it to see that it will crash.
The buffer will be filled with unknown data after the first two known values so the four bytes at BYTE *data... |
Forum: C Oct 14th, 2009 |
| Replies: 5 Views: 301 That is a typical search problem. The given solution is a 'depth first' search where you search down the chain of moves before considering other moves. Potentially more efficient is a 'breadth first'... |
Forum: C Oct 14th, 2009 |
| Replies: 14 Views: 493 Let's try it with my previous example.
struct Header {
DWORD dwMagic;
DWORD dwSize;
BYTE *data;
};
void MyFunction() |
Forum: C Oct 13th, 2009 |
| Replies: 14 Views: 493 In the case of zero sized array, it was generally used as an easy way to index into a variable sized buffer ...
struct Header {
DWORD dwMagic;
DWORD dwSize;
BYTE data[];
};
... |
Forum: C Oct 13th, 2009 |
| Replies: 28 Views: 1,628 Glad it is working. One thing to check though ...
isspace(c) will be true for EOL so you will skip some line endings.
Sorry about the example not building. I've been doing c++ too long.
To... |
Forum: C Oct 12th, 2009 |
| Replies: 28 Views: 1,628 That will leave leading spaces as well.
Besides the fact it is way more complicated than needed. |
Forum: C Oct 12th, 2009 |
| Replies: 28 Views: 1,628 Make it so it's just like the first time so reset both of em ...
#define EOL '\n'
...
if(c == EOL)
{
putchar(c); |
Forum: C Oct 12th, 2009 |
| Replies: 28 Views: 1,628 Close but not quite right Aia.
This will leave a leading space and a trailing space before the line feed.
You can fix yours OSiRiSsk. Just check for the EOL and reset the flags. |
Forum: C Oct 9th, 2009 |
| Replies: 8 Views: 668 Just change your printf("%c" to printf("|%c" and printf("\n" to printf("|\n"
You should probably split the code into sections though, like: ClearArray, FillArray, and ShowArray. Then you can make... |
Forum: C Oct 9th, 2009 |
| Replies: 7 Views: 386 Also it would be a good idea to save strlen(string) and instead of doing strlen in the for loop.
int iLen = strlen(string);
for(i = 0; i < iLen; i++)
... |
Forum: C Oct 9th, 2009 |
| Replies: 28 Views: 1,628 The code as is should work right the first time. If you are reading multiple lines it will start putting leading spaces in because start is not reset for the next one. |
Forum: C Oct 9th, 2009 |
| Replies: 2 Views: 459 The stringSend member should not be part of the structure you send. It is just a 4 byte ptr that will be meaningless to the receiver.
Thus when you send it will be sizeof(struct) - sizeof(char *)... |
Forum: C Oct 9th, 2009 |
| Replies: 8 Views: 668 You can do this without the 'if' checks and with 2 nested for loops.
Break your problem up to it's smallest pieces and choose a path that solves the pieces with the least redundancy.
Smallest... |
Forum: C Oct 8th, 2009 |
| Replies: 5 Views: 301 You'll want to keep your x & y local so each move is incremented from the correct position (you'll need to pass these in as params with the starting position sent in the first call). As it is the... |
Forum: C Oct 8th, 2009 |
| Replies: 5 Views: 301 If speed is not critical use a recursive function.
GenNextMove(int depth)
{
if(depth == nMaxMove)
{
nTotalPos++;
return;
} |