unable to make out how ~ operator works in c
hello, I have this piece of code can you explain me the output unsigned int x=3; ~x; printf("%d",x); output is 10 I am not able to make it how. I have compiled the code on turbo c ...
hello, I have this piece of code can you explain me the output unsigned int x=3; ~x; printf("%d",x); output is 10 I am not able to make it how. I have compiled the code on turbo c ...
I'm trying to import some c code into my c++ program. There are three lines that don't import directly: The first: free(t); The second: new_node = (Tree *) malloc (sizeof (Tree)); The third: Tree * delete(int value, Tree * t) How can these be changed to work in C++? ...
I am working with audio data. I'd like to play the sample file in reverse. The data is stored as unsigned ints and packed nice and tight. Is there a way to call memcpy that will copy in reverse order. i.e. if i had 1,2,3,4 stored as ints in an array could i memcpy and magically reverse them so i get 4,3,2,1 ...
typedef struct Node { int data; Node *next; Node *other; }; Node *pHead; pHead is a singly linked list. The next field points to the next element in the list. The other field may point to any other element (could be one of the previous nodes or one of the nodes ahead) in the list or NULL. How does one write a copy function that...
for() or while() - which is BEST? for (i=1; i<a; i++) /* do something */ OR i=1; while (i<a) { /* do something */ i++; } ...
Could anybody please tell me what is the main difference between C & C++ structures. ...
How would I go about making an array of file pointers in C? I would like to create an array of file pointers to the arguments of main... like a1.txt, a2.txt, etc... So I would run ./prog arg1.txt arg2.txt arg3.txtto have the program use these files. Then the argument for main is char **argv From argv, I would like to create the array of...
I am wondering is there any function that would return the current time in seconds, just 2 digits of seconds? I'm using gcc 4.4.2. ...
I’ve googled quite a bit, but I can’t find information on how variable-length strings are generally implemented in higher-level languages. I’m creating my own such language, and am not sure where to start with strings. I have a struct describing the string type, and then a create function that allocates such a ‘string’: /* A safer `str...
I remember reading somewhere that it is better to use integers as loop counter variables rather than char or short. If yes, why? Does it provide any optimization benefits? ...
Assume I have a file pointer FILE* myfile. Is there a way to retrieve the name of the file where myfile is reading from or writing to? ...
Hello I have this code for a school assignment, but i can't manage to format it. When i run the program i keep getting 1.27768e-307. lp->price is a double with the value of 1000000.0000000000 printf("Price of flat: %g\n", lp->price); Any ideas? The other double values gets formatted correctly, just not price. ...
When constructing a lexer/tokenizer is it a mistake to rely on functions(in C) such as isdigit/isalpha/... ? They are dependent on locale as far as I know. Should I pick a character set and concentrate on it and make a character mapping myself from which I look up classifications? Then the problem becomes being able to lex multiple chara...
Hello, I am looking for an efficient algorithm in C to bitwise-transpose 8 bytes of data. What I mean with this is that if I have 8 bytes like this: 00011100 00111000 00000001 00000000 11000000 00000000 11111111 01010101 I want to get the following 8 bytes: 00001010 00001011 01000010 11000011 11000010 10000011 00000010 00100011 An...
I came across a interview question that asked to remove the repeated char from a given string, in-place. So if the input was "hi there" the output expected was "hi ter". It was also told to consider only alphabetic repititions and all the alphabets were lower case. I came up with the following program. I have comments to make my logic c...
Hey, Can anybody please help me make sense of this error message? *** glibc detected *** ./kprank_new3_norm: munmap_chunk(): invalid pointer: 0x00000000096912d0 *** ======= Backtrace: ========= /lib64/libc.so.6(cfree+0x1b6)[0x3df6e75a36] ./kprank_new3_norm[0x409277] ./kprank_new3_norm[0x4092a9] ./kprank_new3_norm[0x4092ea] ./kprank_new3...
Hi, I am trying to read some text from a file and write it to another using open(), read() and write(). This is my open for the file-to-write-to (I want to create a new file and write into it): fOut = open ("test-1", O_RDWR | O_CREAT | O_SYNC); This is setting file-permissions to something I don't understand at all. This is the outp...
I've written a shared library which is partly used by a Windows application written in Visual Studio 6 (pure C). The library works flawlessly under Linux, but under Windows something's broken somewhere (it uses some #ifdef WIN32 which might enclose something errornous). But adding the library DLL as "additional DLLs" to the project in ...
Another socket problem. In my client code, I am sending some packet and expectign some response from the server side: send() recv() <-- it is blocking Immediately after send(), the server crashes and rebooted itself. In the meantime the recv() is waiting. But even after the server is up, the receive call is hanging. I have ad...
I have an application implemented as an ISAPI filter whose behavior needs to change depending on whether it is being loaded by ISA or IIS. During GetFilterVersion it needs to register for SF_NOTIFY_SEND_RAW_DATA if being loaded by ISA or SF_NOTIFY_SEND_RESPONSE if being loaded by IIS. There doesn't seem to be any information about the s...