Forum: C Apr 7th, 2009 |
| Replies: 3 Views: 1,192 The wait() (http://linux.die.net/man/2/wait) function monitors the state of a process, not its I/O streams. What you really want is the poll() (http://linux.die.net/man/2/poll) or select()... |
Forum: C Apr 1st, 2009 |
| Replies: 2 Views: 575 I'm sure your instructor has given you much more information than you have given us.
Make sure you review how to open pipes:
man 7 pipe: overview (http://linux.die.net/man/7/pipe)
man 2 pipe:... |
Forum: C Jan 31st, 2009 |
| Replies: 1 Views: 437 No.
Automatic variables are freed:
int foo()
{
int a = 42;
int* p = (int*)malloc( sizeof( int ) );
*p = a; |
Forum: C Jul 19th, 2008 |
| Replies: 10 Views: 1,099 Salem is right. I almost said something about that myself but it has been a while since I've used select() and I forgot you aren't waiting on stdin (even though your comments say you are).
To wait... |
Forum: C Jul 18th, 2008 |
| Replies: 10 Views: 1,099 The FIFO will never have input until you write something to it. Since you don't write anything to it, select() will always say that there is no input waiting.
Remember, a FIFO must be open at both... |
Forum: C Jul 11th, 2008 |
| Replies: 4 Views: 561 I think you need to spend some time tracing through your algorithm. I'm not sure exactly what it is supposed to do, but I don't think it is doing what you want it to do...
(Given "HELLO", the list... |
Forum: C Jul 2nd, 2008 |
| Replies: 8 Views: 690 Dev-C++ uses MinGW.
And AD only said he has seen the problem, not that he tried compiling OPs code.
The problem likely stems from the 16-bit executable trying to do something in a way that XP... |
Forum: C Jul 2nd, 2008 |
| Replies: 8 Views: 690 Here's a wild stab in the dark: you are using a really old compiler like Turbo C.
If I'm right, then you should visit one of the following and get yourself a compiler that makes 32-bit... |
Forum: C May 20th, 2008 |
| Replies: 10 Views: 1,015 His assignment is to combine every two words thus:
<word0> <word1> --> <word0 replaces each consecutive sequence of digits in word1> |
Forum: C May 18th, 2008 |
| Replies: 10 Views: 1,015 Hmm... I thought that was a C++ thing. Well, I've learned something.
Alas, sorry for the late night quick diagnosis.
Your algorithm assumes that the very first character in the string is a... |
Forum: C May 17th, 2008 |
| Replies: 10 Views: 1,015 Don't do this:
char recordd[sizeof(record)] = {0};
It isn't doing what you think it is.
As another hint, you should compile using the -Wall option. I did and it told me, right off the bat... |
Forum: C May 17th, 2008 |
| Replies: 8 Views: 871 R U Japanese? (osu?)
You have misunderstood the purpose of #include files.
Each separate module (.c file) should be compiled separately (into a object file: .o or .obj).
Each module should... |
Forum: C May 16th, 2008 |
| Replies: 8 Views: 1,667 Good grief!
n.aggel, you had the right idea to begin with, only your syntax needs help. Don't change the definition of the function, but just pass the appropriate pointer.
void... |
Forum: C Feb 9th, 2008 |
| Replies: 4 Views: 690 That's because commands in the cwd are not in the PATH by default on Linux/Unix.
Type ./a.out
Enjoy! |
Forum: C Jan 22nd, 2008 |
| Replies: 4 Views: 2,030 Ah, the loop ends at the space because the string ends at the space. scanf stops reading input at spaces. So when you enter "1234 432" the userString gets "1234", and " 432" is left waiting to be... |
Forum: C Jan 19th, 2008 |
| Replies: 12 Views: 8,045 I too fail to see how complaining about the OP's tools helps him answer his question. There is no need to give him/her a hard time.
In the real world of capitalism, choice of toolset is entirely... |
Forum: C Jan 17th, 2008 |
| Replies: 6 Views: 2,133 No, you've completely missed the concept of argv.
argv is an array of strings (where a string is a pointer to char). It is not safe to change argv.
argc is the number of items in the argv array.... |
Forum: C Jan 15th, 2008 |
| Replies: 2 Views: 3,693 The first is local data you can edit (since the array is local data).
The second is a local pointer to global, static (constant) data. You are not allowed to modify constant data.
If you have... |
Forum: C Jan 4th, 2008 |
| Replies: 5 Views: 2,149 Agreed, but when dealing with new programmers I have learned by experience (teaching and tutoring) that debugging works best once a firm concept of what should be happing is established. Anyway... |
Forum: C Jan 4th, 2008 |
| Replies: 5 Views: 2,149 I always take it a step farther and just tell people to forget the code. Get out the paper and crayons first, draw what must happen, then write the code to do exactly that.
Disentangling new... |
Forum: C Jan 1st, 2008 |
| Replies: 5 Views: 876 My best guess is that the argument is a "type-cast expression" (according to MSDN (http://msdn2.microsoft.com/en-us/library/0w557fh7(VS.71).aspx)), which always takes the form:
(typename)
This... |
Forum: C Jan 1st, 2008 |
| Replies: 5 Views: 876 Line 19 should read
newp = (nameval_t *) malloc( sizeof( nameval_t ) );
This is why I recommend just always using parentheses with sizeof. It always works with parens, but makes a difference... |
Forum: C Dec 30th, 2007 |
| Replies: 3 Views: 4,725 You are making two errors:
1.
The type of Q.Data[n] is a Flight (aka ItemType) --not a pointer. You cannot assign NULL to a struct.
When I tested it, the following compiled correctly:... |
Forum: C Dec 15th, 2007 |
| Replies: 4 Views: 759 Destructively or non-destructively?
Why do you have so much indirection? |
Forum: C Dec 9th, 2007 |
| Replies: 8 Views: 920 Ah, I have learned something. (Further proof that C99 is weird...) |
Forum: C Dec 8th, 2007 |
| Replies: 8 Views: 920 It's probably in your
while (status != EOF || status2 != EOF)
statement.
That || should be an &&.
Oh yeah, don't int main(void).
Always use either:
1. int main()
2. int main( int argc,... |
Forum: C Dec 5th, 2007 |
| Replies: 3 Views: 731 Please use code tags.
Think about why that messes up and you'll be able to fix it easily. You are on the right track.
Also, there is a special case for the very first line. |
Forum: C Dec 5th, 2007 |
| Replies: 3 Views: 731 You need to count how many lines there are.
Every time you read '\n' from the file, increment your current line number and print it to the file.
Hope this helps. |
Forum: C Nov 23rd, 2007 |
| Replies: 14 Views: 1,513 Actually, it is the preprocessor: cpp. Modern preprocessors are a lot smarter than they used to be. They actually tokenize the input. By using the "traditional" cpp mode, where the strings are simply... |
Forum: C Nov 23rd, 2007 |
| Replies: 14 Views: 1,513 I get the following output:
-201 -16
3.141
Did you compile with gcc -traditional-cpp ?
The printf statement just uses as few characters as needed to work.
4. floating point number
* |
Forum: C Nov 23rd, 2007 |
| Replies: 14 Views: 1,513 Ah.
If you want to see it in action why don't you write something that traces the values of the variables F and OO?
If you do, you'll see that it uses a cheap trick based upon the circular... |
Forum: C Nov 22nd, 2007 |
| Replies: 14 Views: 1,513 It's just a giant math expression.
Why are you trying to learn programming by looking at programs that are specifically designed to be hard to understand? |
Forum: C Nov 22nd, 2007 |
| Replies: 14 Views: 1,513 That program computes an approximation of PI by computing its own area. If you want to get more digits out of it, write a bigger program. [1... |
Forum: C Nov 15th, 2007 |
| Replies: 7 Views: 2,615 You are on the right track. The only problem is that char is a single character, not a whole list of them (or array of them). You probably want to use a pointer to an array of chars.
Also, don't... |
Forum: C Nov 6th, 2007 |
| Replies: 9 Views: 1,303 "A" is a string.
'A' is a char.
code is a char.
Hope this helps. |
Forum: C Oct 19th, 2007 |
| Replies: 7 Views: 865 Actually, you've got things just about right. The problem is that you are calling main() from the other functions. Don't do that.
In between lines 16 and 17 add:
while (TRUE) {
end the... |