Initializing un-initialized variables before use is good
practice in all instances. If you really feel the memset
will give you a performance hit then you should design
your code so that your variable is initialized at compile time
(global) or in the declaration or use pointers.
However, the...
You would use "memset" to initialize the memory
allocated by the statement...
char proddir[20];
...since this is declared inside "main()", it
is local in scope and allocated on the stack.
These types of variables (automatic) are not
initialized and it is always good...
What part of the code gave you a core dump?
I assume that it may be later on (after the switch)
when you are actually using "poddir". Your code may
require "writable" space at "proddir" in which case
char *proddir = "Food"; will point to...
try using...
echo -e "Enter your name: \c"
The "-e" enables interpretation of the "backslash"
escape characters (i.e. "\c")
declare your variable as...
char *proddir;
...the compiler is complaining about the fact that
you are assigning a predefined array "proddir[20]"
to a constant (which is stored on the heap). This does
not copy the data it just tries to reassign the
pointer to the memory allocated for...
You could first create all the subdirs first...
mkdir main
mkdir main/sub1
mkdir main/sub1/sub2
...then do...
chmod -R 775 main
...this will do a recursive "-R" chmod starting
at "main"
Well if you're going with new equipment,
I would also go with new software. I would
think that you would get some Windows GUI
software with the new scales anyway.
In any case, you may have difficulties building the
Borland code on the new system.
If you really want the "long" mixed in...
...
char buf[128];
long year = 2002L;
sprinf(buf, "Hello World %ld\n", year);
...subtle difference :)
Normally you would just read for the number
of bytes you want then go do somthing.
In your code, the only thing that will
break you out is some sort of signal or error
(ie. the other end disconnects you get a broken pipe)
You can also set up the socketfd in a "poll" fdset
and...
Well... it's been a long time since I've done any DOS
programming but from the looks of it, I'm assuming you have
a device (scale?) attached to the serial port at COM2
from the line...
int portbase = 0x2f8; /* I assume you meant "=" and not "-" */
...Again, making (lots of)...
use the localtime() function. It returns a struct of type tm
struct tm *localtime(const time_t *clock);
The members of the tm
structure are:
int tm_sec; /* seconds after the minute - [0, 61] */
/* for leap seconds */
int tm_min; /* minutes after...
try...
do
{
if(fread(&partrecord, sizeof(part), 1, inp) < 1)
{
if(feof(inp) != 0)
{
fclose(inp);
break;
}
perror("fread");
... we may have been interrupted
... and may have some data in the buffer
fclose(inp)...
All kinds of ways (how do you think the "date"
command works?)
Anyway, you also have "asctime()"...
SYNOPSIS
#include <time.h>
char *asctime(const struct tm *timeptr);
DESCRIPTION
The asctime() function converts the broken-down time in the
structure pointed to by...
There are at least a half a dozen ways to do this
and here's one...
In your program, setup a character pointer and an array
buffer of some size...
char *p, buf[1024];
...then open the file for reading...
fd = open(...)
...then read into the buffer...
while(read(fd, (void *)buf...
Well... I don't know what your current "contracts" with these clients
look like but in cases like this, you don't really have many options.
The client may have a very heterogenious environment in which
all possible "side-effects" just cannot be realistically accouted for.
In...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.