Thanks, I will take that into account!
Type: Posts; User: flexo87
Thanks, I will take that into account!
Hi everyone,
as the title states I have a question about templates definitions. I have defined a Stack<T> class and a BinaryTree<T> class and both work fine, in fact I can have stacks (or trees) of...
If you are writing C code, then my suggestion is to compile using gcc. A few tips:
-Since you have a bash shell, when you don't know how a function works, use manual (eg. type "man srand")...
You can wrap the matrix inside a struct declaring it as a char m[ROWS][COLUMNS], where ROWS and COLUMNS are macros. Then you can have a pointer to the struct and allocate it dynamically. Of course...
Yeah you're right!!... but in any case I would have got warnings not compiling errors!! (if we have to be pedantic!) ;)
[flexo@localhost ~]$ gcc who.c -o who
[flexo@localhost ~]$ ./who
What is your name?flexo!
Darn glad to meet you, flexo!!
[flexo@localhost ~]$ gcc --version
gcc (GCC) 4.4.2 20091222 (Red Hat...
The algorithm it's fine, use another reference which points to the Kth-node. Where K is the the value of the variable count, and use it to add the current node to the end of the list. Otherwise you...
For the first to loops it works, but after, that code assigns to the first successor of the head, the current node. That means you have a list with only two elements and each round you lost the...
If you want to work on a parameter and modify its value, you need to work on its address. filelist is a pointer to your struct, but when you modify this value in the function (malloc), only the...
>The malloc is actually lost because you are passing it to the function. If you really need to pass it, you need a pointer to a pointer, and to pass the address of the variable, rather than passing...
Hi, if your struct is declared as a global variable, why do you need to pass it as parameter to the function load_file_list()?... you can access to it from the functions written on the same file, so...
..Try to put the srand() call as you wrote it, in the function as you don't use rand().
main_prog.c
..............
int random_value;
.............
srand(time(NULL)); //
random_value= my_random(limit); // here I call my funct
....
Where did you declare ant...
Use strtok(), it's not a bad idea!...Take a look at the manual.
PersonList *copyt(PersonList *allPersons) {
int max=0,numfr=0;
PersonList *newlist=0;
while(allPersons)
{
newlist=(PersonList*) malloc(sizeof(PersonList));...
yes, why does your function not return anything? in that function you can modify the list but you can't change the value of "PersonList* allPersons" which is a pointer. thus the assignment...
If you copy it you won't affect anything, but you have to go through the list and, copy each node, and put it into the new list. you can't just assignment newlist->next.... because you would work on...
What do you mean?.. do you want an empty list point to another? in that case you would assign the head of the old list to the head of the new one.
char *p=NULL;
if (!p) printf("p is null");
else printf("p is not null");
keep in mind that if i didn't write the assignment (p=NULL) its value would be undefined and the if statement wouldn't...
It is not the same, with the first (int** x) you are telling the compiler to not allocate memory for the array (you will do it in the program).
with the second (int *x[10], i thnk brackets are...
>Also, & means 'address of', so unless you're trying to actually display the address of something, you shouldn't be using it in printf
s is an array of chars, so '&(s[N])' in a printf with the...
These are two kinds of declaration for an array of integers:
int x[10]; /* allocated at compile time, each position has the size of an int */
int *x; /* it's the same with the...
You should also check the value that scanf returns. It in fact tells you how many parameters have been correctly read. if you put 'x' and your scanf waits for an integer (%d) it will return 0, so if...
if it is FIFO, the oldest is the tail of the list isn'it?
if((pnt->next)==NULL)
{ c=head->nodecode;
h=NULL;
printf("%d\n",c);
}
> lines = (char **) calloc(1, sizeof(char));
lines is a pointer to a pointer to a char, and you are allocating the memory for a char not for a char*.
it should be:
lines=(char**)calloc(1,...