Fair enough.
Your examples don't cover* unbuffered input streams (like one would find on a microcontroller), but I think that you've proven your point
*I think that "don't cover" is incorrect -...
Type: Posts; User: Click_here
Fair enough.
Your examples don't cover* unbuffered input streams (like one would find on a microcontroller), but I think that you've proven your point
*I think that "don't cover" is incorrect -...
Barney, it was good for you to provide that example for academic purposes.
However, the bottom line is: There is no reason why you should be using "gets".
No
My point is that a gun is always dangerous and it is not designed to flick a light switch on and off - It is a job that you would use your hand for, but I have created a stupid, redundant way...
I wasn't talking about firing it at the light switch - Just flicking the switch with it.
To me, it's like saying that a gun is safe, because it can be used to turn on and off a light switch.
Just following on from laserlight -
"strcpy" does not have to have external input as it's arguments, "gets" does.
I read about gets_s in the C11 draft - But as you said earlier, it's a draft. And point 6 for the gets_s function in that draft recommends the use of fgets instead of get_s anyway.
Strncpy is your best bet with a definition for the maximum string length.
If you wanted to have a faster program, define the strings and separate pointers to point to them and then change where...
I think that that is bad advice in this case -> Think about this example
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define STR_MAX 16
Do NOT use "gets"
I wouldn't worry about that mistake -> It is quite common for people just learning C to get arrays and pointers mixed up.
Also note how I've declared main as "int main" - And I have given it a...
This is what I meant - And I neatened up your code. Enjoy.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define STR_MAX 16
You are declaring a,b,c,d as pointers.
If you declare them as string literals, you may not modify them.
You will need to declare them as arrays large enough to hold the biggest string.
...