3
Contributors
8
Replies
9
Views
10 Years
Discussion Span
Last Post by iamthwee
0

most probably because you can't do strlen(UNKNOWN). It's like saying strlen("hello") which obviously ain't gonna work.

Why not just initialise it properly? If you don't know how, you're way out of your depths.

Also Fgets why the capitalization? gets why?
feof Again why? I could go on.

0

Actually, you can do strlen(UNKNOWN). Give it a try and see that it works.

#define UNKNOWN "Unknown"
#include <stdio.h>


int main ()
{

printf ("%d", strlen(UNKNOWN));
    
}

The above program prints 7.

I do it with #DEFINE because that is how the instructor wants it. If I did it otherwise, I would get penalized. It already happened before.

Fgets is because I use a wrapper function for fgets (also required). This code is all based on stuff in a UNIX socket programming book.

I just found out what the problem was. The client uses Readline (sort of an fgets) for reading the server output... so everything that I send from the server has to be \n terminated. Yes, I know. I also can't beleive how much time I wasted on something this trivial.

0

I dunno, I don't really use c. I don't know what you mean by add a newline at the string. But glad you sorted it.

0

fgets reads until x (size of buffer) amount of characters are read OR a newline character is encountered. In my case, the buffer was quite large, so the client's fgets was waiting till either the buffer was full, or a newline character was sent.... and since I wasn't sending a \n, it kept waiting. That was the problem.

0

>Missing a semicolon.
Do you practice being obtuse?

>I dunno, I don't really use c.
Then maybe you shouldn't be trying to answer questions about C.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.