so i finally got the server.c program to run in linux environment i was elated to start the client.c program it turned out that there would be another problem.

below codes are the codes of client program i compiled it and it produced an exe but there is a warning that say's there is no new line at the end of file. what should i do?

WARNING: NO NEW LINE AT THE END OF FILE

another question is.. how will it affect my client.exe? i don't really know what to expect once you run the programs. please explain?

// this part of the code is in the last part this is where the problem lies..

	while(0<(status=read(clientSocket,buffer,sizeof(buffer)-1)))
		printf("%f: %s", status,buffer);
	if(-1==status)perror("read()");
	close(clientSocket);
	return 0;
}

Dani AI

Generated

Two separate things are in play: the compiler warning about a missing final newline, and how to test a simple client/server on a single machine. and already pointed to quick fixes; the notes below add practical, low‑risk steps and a few debugging tips that address gaps in the thread (for example, a printf format bug in the posted snippet).

The newline warning comes from the way C/C++ source is tokenized (many tools expect each physical source line to end with '\n'). In almost all cases the produced executable is fine, but some tools (the preprocessor with backslash-line-splices, patch/diff, or automated builds) can misbehave. A quick way to fix many files in a repo and to avoid repeated warnings is to make editors add the final newline automatically (an .editorconfig entry insert_final_newline = true works across many editors). For a one‑off shell fix, this will append a newline only when missing:

if [ "$(tail -c1 client.c | wc -l)" -eq 0 ]; then
  printf '\n' >> client.c
fi

For testing the server/client on one PC: using a VM is fine (), but the simplest is the loopback interface. Start the server in one terminal and connect from the same host with 127.0.0.1 and a different terminal. For manual checks use netcat/ncat for a quick smoke test:

# terminal A: listen on port 12345
nc -l 12345

# terminal B: connect to it
nc 127.0.0.1 12345

Common pitfalls to watch for: bind address (0.0.0.0 vs 127.0.0.1), firewall rules, and running as non‑root for ports <1024. Verify the server is listening with ss -ltnp or netstat -anp.

A few concrete code/debug tips missing from the thread: do not print the number of bytes read with the wrong printf specifier (use %zd for ssize_t), always treat read() returning 0 as EOF and -1 as error, and null‑terminate the buffer before using %s (or write the exact byte count with write() instead of using %s). For background reading about the warning see this explanation on StackOverflow: Why is "no newline at end of file" a warning? and for quick manual socket tests see ncat: Nmap Ncat.

Recommended Answers

All 5 Replies

>WARNING: NO NEW LINE AT THE END OF FILE
>What should I do?

Move your cursor to the end of the latest line of your file and press ENTER.
Then try recompiling your source, the warning should be away.

commented: Your wisdom is endless, all bow to the mighty tux ;) +20
commented: Free food for the gimme question :) +36


another question is.. how will it affect my client.exe? i don't really know what to expect once you run the programs. please explain?

It won't affect it at all -- just put the blank line at the end of the file like the warning message asked you to do.

I'm surprised there are still compilers that produce that warning message. I haven't seen it in more than 15 years.

I'm surprised there are still compilers that produce that warning message. I haven't seen it in more than 15 years.

I actually see this warning quit often. I compile a lot of stuff for microcontrollers and all those compilers complain about it.
Most texteditors put a '\n' after each line automatically, so perhaps even 'modern' compilers will complain about it when you give them a file created with something oldschool like 'edit' ?
As far as I know, it's still part of the C++ standard that you can't end a file without a new-line (or a backslash with a new-line) because the behavior will be undefined.

commented: That clarifies the whole thing :) +11
commented: Good post +36

thanks guys..
now another question is how will i test the hello world server/client program.
can i use only 1 pc someone said i should use 2? since its a networking program is that correct?

thanks guys..
now another question is how will i test the hello world server/client program.
can i use only 1 pc someone said i should use 2? since its a networking program is that correct?

You could use what's called: 'a virtual pc'
In that case it's like you have two pc's (but in fact you only have one real pc, and on the real pc you run a kind of emulator software, this is software which emulates the hardware of a pc. In that emulated computer, you can install another operating system, connect it to a network...), but you'll have to make sure that your current pc has enough RAM to run the Virtual Machine on of course.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.