struct temp_Packet{
int src, dst, typ, prt;
char data[51], buffer[51];
}temp;
//end of temp_Packet
struct SPackets{
int _src[50], _dst[50], _typ[50], _prt[50];
char...
Type: Posts; User: rpet
struct temp_Packet{
int src, dst, typ, prt;
char data[51], buffer[51];
}temp;
//end of temp_Packet
struct SPackets{
int _src[50], _dst[50], _typ[50], _prt[50];
char...
Quick and dirty:
double drand48() // random number between [0.0, 1.0]
{
return rand() / (double)RAND_MAX;
}
...
&p.id is a memory address.
printf("Id: %d \n",&p.id);
should be:
printf("Id: %d \n",p.id);
if ((data = fopen("data.txt", "rb")) == NULL)
{
printf("Erro ao abrir ficheiro\n");
}
If the file could not be opened, you print a message and... continue to read as though nothing had...
Just do it:
int howmanyrooms()
{
int rooms; /* local variable */
...
while(!feof(fp)) {
fscanf(fp,"%s %s",&e.id,&e.name);
...
The EOF-flag is not set when the last element was read successfully; it is set when the first read operation has failed. That's...
In that case, the "null"-string would be what I called "some special value that seems appropriate". But keep in mind that the record size must not change. Otherwise your file structure is broken and...
There are two ways to do this:
1) Copy the file - record by record - and skip the one you want to delete.
2) "fseek" to the record and mark it as "deleted", i.e. overwrite the name with some...
There are actually two problems here. The first one is to find an algorithm that re-orders the array the way you want, and the second one is to translate it into a correct c++ program.
To...
Try to get a more detailed error message using "errno":
#include <errno.h>
#include <string.h>
...
if (connect(....) == -1) {
That's right. 0.90 using buffered input...
#include <stdio.h>
#define N 0x80000
unsigned char inputv[N];
Elysia, gets() is dangerous and atoi() may fail. You're correct on this. I know that. But this discussion is about to find the fastest solution for a given problem. So let's concentrate on that and...
2.14, using an atoi() replacement
#include <stdio.h>
int main()
{
char b[11];
unsigned int i, v, n, k, count = 0;
Nothing's wrong with gets() in this special case!
scanf() contains some sort of (slow) parser, that we do not need here. Replacing scanf() by gets() and atoi() results in 3.4 (s?) instead of 5.4.
#include <stdio.h>
int main()
{
char...
You cannot assign an array like this. Exception: When the array is defined.
int i[5] = {1, 2, 3, 4, 5}; /* ok */
int i[5]; /* definition is here */
...
i = {1, 2, 3, 4, 5}; /* fails,...
The second time your program reaches the loop header, i is 3, and a[3] is undefined at this point.
By pure chance a[3] is 0 and the execution stops.
Your program does something different. Check the while / for / fgets part.
Due to mode "a+" the new record is always appended at the end of the file. Replace 'a+' by 'w+' and your program should work.
Sorry, I thought I clarified it already.
Adding a variable name to a function prototype is optional. The compiler does not care about it, so we cannot say if it is right or wrong. Each programmer...
There is a difference between variable names in function prototypes and the usage of global variables.
I said, the variable names are of no use, not that global variables are good.
This is...
Good programming practice is a matter of personal taste - nothing more. The more people agree with a specific practice the more it is considered "good", no matter if it's really useful or not.
Not in my opinion.
The "correct" level of documentation depends on the programmer, its coding abilities, experience and taste. Example: Hungarian Notation makes the code undoubtedly more...
I never use variable names in function prototypes.
They are very helpful in man pages and other documentation, but program != documentation.
The concept of prototypes was invented to tell the...
You should a map work if it cannot compare its keys?