I have problems swapping adjacent nodes in a linkedlist.
for ex: input : 1->2->3->4->5->null
output: 2->1->4->3->5->null
bool swapAdjacent(node** head)
{
//1->2->3->4->null
//2->1->4->3->null
if(head==NULL)
return 0;
node* current = *head;
*head = (*head)->next ;
node* prev = NULL;
cout<<"head val "<<(*head)->data <<endl;
...
Is it possible to use rand() or any other pseudo-random generator to pick out random numbers, but have it be more likely that it will pick certain numbers that the user feeds it? In other words, is there a way, with rand() or something else, to pick a pseudo random number, but be able to adjust the odds of getting certain outcomes, and h...
For some reason I can't seem to catch the WM_LBUTTONDOWN event on a label ("STATIC" window). When monitoring with Winspector it appears the message always arrives to the parent window. However, according to the docs, the message should be posted to the Window beneath the cursor.
Does anyknow have an idea why the message does not arrive...
I have a C (not C++) struct that goes like this
typedef struct mystruct{
float a,b;
int x, y;
} mystruct;
Then in a function I collect data like this:
mystruct List[MAX];
ListNumber = 0;
for(i = 0; i < MAX; i++)
{
if(conditions_meet)
{
List[ListNumber].a = masterlist[i].a;
...etc
ListNumber++;
}
}
then I send the array to ...
Hi
I am new to linux c programming and i have a simple program just for learning and when i compile it it gives me error "dereferencing pointer to incomplete type" here is my code
struct Node
{
struct Node* left;
struct Node* middle;
struct Node* right;
int nodeData;
int nodeLevel;
char isVisted;
};
struct List...
hello i am trying to sort a linked list
when i sort it it works on visual studio but when i move it to linux the linked list does not get sorted for some reason.
my sorts gets a pointer to a pointer of the list and this is my sort code:
i call the function like this:
SortQueue(&pprocessQueue, ProcessPrIdCompare);
and here is my function...
I have a Bison rule
block: LBRACE { some code } decls stmts RBRACE {more code }
;
The issue is in the "more code" section, I have
$$ = $3 ;
Basically, I want the return value of block to be stmts. When I do this, Bison says "$3 of block has no type." If I remove the code block containing some code and stick it into the latt...
I'm trying to find a lightweight cooperative threading solution to try implementing an actor model.
As far as I know, the only solution is setcontext/getcontext,
but the functionality is deprecated(?) by Apple. I'm confused by why they did this; however, I'm finding replacement for this.
Pthreads are not an option because I need cooper...
I would like the executables for a project I am working on to have the latest mercurial changeset recorded so that when a user complains about buggy behavior, I can track which version they are using. Some of my executables are Python and others are compiled C. Is there a way to automate this, or can you point me to projects that exhibit...
As most other people, I deal with file I/O a lot and I wanted to make sure that I wasn't losing time on reading the file. I currently know of FileReader() as the most efficient way to read files in Java, but I was hoping there would be something obscure that was better.
Also, can you skip reading a line in a file in Java/C?
...
Possible Duplicate:
Sell me on using const correctness
In C (and I guess C++ as well), is there any particular reason to declare a variable const other than to prevent yourself from modifying it by mistake later on? Are const variables treated differently at compile time other than the fact that they aren't allowed to be modif...
I'm using libxml2 to parse HTML. I want to remove certain formatting tags like <center>, while keeping their content (for example, a link).
This means I'll have to remove certain child nodes from my xmlNodeSet, but keep that node's children.
Right now, I got this code:
xmlNodePtr parentNode = nodes->nodeTab[i];
if (parentNode != NULL...
I'm just learning to code in C, and I wan't to know if anyone can point me in the right direction, or give me an example for a simple HTTP Get request in C.
Thanks :)
...
Given a literal memory address in hexadecimal format, how can I create a pointer in C that addresses this memory location?
Memory addresses on my platform (IBM iSeries) are 128bits. C type long long is also 128bits.
Imagine I have a memory address to a string (char array) that is: C622D0129B0129F0
I assume the correct C syntax to dir...
I'm going through the code of Unix version 6 with the Lion's book. One of the header files (param.h, can be accessed here) defines the following structs:
/*struct to access integers*/
/*single integer */
struct { int integ; };
/*in bytes*/
struct { char lobyte; char hibyte; };
These structures don't seem to define any instance, nor...
Hello,
gcc 4.4.4 c89 valgrind 3.5.0.
I am getting a leak detected when I open file using a file pointer.
==17681== in use at exit: 352 bytes in 1 blocks
==17681== total heap usage: 1 allocs, 0 frees, 352 bytes allocated
==17681==
==17681== 352 bytes in 1 blocks are still reachable in loss record 1 of 1
==17681== at 0x400...
I used this code to read file. But fread function always return 0. What is my mistake?
FILE *file = fopen(pathToSourceFile, "rb");
if(file!=NULL)
{
char aByte[50000];
int ret = fread(aByte, sizeof(aByte), 1, file);
if(ret != 0)
{
not jump into there;
fseek(file, 0, SEEK_SET);
fwrite(aByte, ret, 1...
Hi I wonder if anyone could give me an example how the
TickGetDiv256(); function works. It came from Microchip in Tick.c
Im trying to count for 2 houre's, if fullfilled an engine will be stopped.
I could might use "threshold = tick + TICKS_PER_SECOND * 60;" function.
But I dont know if it would be good to use it for this amount of time...
I was given a DLL that I'm trying to use. The DLL contains the function "send".
this is what I did:
#include <stdio.h>
#include <Windows.h>
int main(int argc, char * argv[])
{
HMODULE libHandle;
if ((libHandle = LoadLibrary(TEXT("SendSMS.dll"))) == NULL)
{
printf("load failed\n");
return 1;
}
if (Ge...
I was discussing C programming styles with some students and when we were talking about comments, one of them noted that he doesn't use C++ comments in C code because they are a bad idea. Turns out that it was based on personal experience with multi-line C++ comments, but it's not the first time I've heard that claim. So, is // considere...