Came across this example in the book im reading and it didn't make sense at all to me, I'm probably missing something but it seems like youre assigning count with the values '10' and then the value 'x' which isnt even an int. Just wondering if this is a syntax that is valid.
The book says this:
The variables count and x are declared to...
Hi I have the following program to check the send buffer size for a UDP socket. However, I the return value is a bit confusing to me. I use the following simple app:
#include <sys/socket.h>
#include <stdio.h>
int main(int argc, char **argv)
{
int sockfd, sendbuff;
socklen_t optlen;
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if(sockf...
After a quick scan of related questions on SO, I have deduced that there's no function that would check the amount of memory that malloc has allocated to a pointer. I'm trying to replicate some of std::string basic functionality (mainly dynamic size) using simple char*'s in C and don't want to call realloc all the time. I guess I'll need...
Hi all. I have some legacy C code (as a macro) that I am not allowed to change in any way, or replace.
This code (eventually) outputs out a digest (C) string based on the source string, performing an operation on the hash value for each character in the string.
#define DO_HASH(src, dest) { \
unsigned long hash = 1111; // Seed. You ...
How would a programmer like myself learn how to find an inverse exponential of a number? on my calculator 2nd LN or e^x. It is similar in concept to the neperien function on calculator e.g. the log of 2 is about 0.3
and the inverse log or 10^x of 0.3 is 2.)
Note: This is to be used within an iPhone project using iPhone SDK
Note: Her...
I don't understand why the ABI is important context of developing user-space applications. Is the set of system calls for an operating system considered an ABI? But if so then aren't all the complexities regarding system calls encapsulated within standard libraries?
So then is ABI compatibility only relevant for running statically link...
Hello friends, I have to modify firefox to make it an automated client for testing some personal servers.
I have to:1.Have firefox connect normaly, send the GET HTTP, and run all scripts on that web page. 2.Firefox does not display the page but save it to a file. I have not yet red the documentation, or the source, sorry. I want some hin...
I have this sample code for converting 32 bit integers to ip addresses.
#include <stdio.h>
int main()
{
unsigned int c ;
unsigned char* cptr = (unsigned char*)
while(1)
{
scanf("%d",
printf("Integer value: %u\n",c);
printf("%u.%u.%u.%u \n",*cptr, *(cptr+1), *(cptr+2), *(cptr+3) );
}
}
This code gives incorrect output for...
I'm writing a simple code editor for the LC3 assembly language, and I've run into a small problem. LC3 assembler outputs basic information about the status of assembling which I'm trying to display in my program after reading it back from the log file.
Originally I attempted to use system() to call the LC3 assembler and redirect the std...
In C language, how to get struct's start address from its member's address?
struct type1 {
//...
int member1;
//...
};
struct type1 obj1;
And ptr1 is the address of member member1 in obj1, how to define
macro #define start_add(ptr1, type1, member1) to get obj1's
start address?
...
I want to write a library for my Arduino(header and class files), but I don't know what tools to use for this job and how to test and debug them.
The Arduino IDE just helps in writing plain programs for direct bootloading, not full project management thing (correct me if I am wrong and guide appropriately with relevant references).
Ple...
what is the minimum number of times the while loop is executed?
Is it zero?
Not talking about DO
...
I got a char array, a huge array char p[n] read from a txt like.
//1.txt
194.919 -241.808 234.896
195.569 -246.179 234.482
194.919 -241.808 234.896
...
foo(char *p, float x, float y, float z)
{
}
I tried to use atof, strtod, but they are real time consuming when the array is too huge, because they will call the strlen(). and the s...
Hello,
I have a string command I'd like to execute asynchronously while writing to its input and reading its output. Sounds easy, right, the devil is in the cross-platform. I'm targeting both MSVC/Win32 and gcc/Linux and obviously want to write the minimum amount of platform-specific code. My google-fu has failed me, I get too much nois...
I'm posting this on behalf of a friend since I believe this is pretty interesting:
Take the string "abb". By leaving out
any number of letters less than the
length of the string we end up with 7
strings.
a b b ab ab bb abb
Out of these 4 are palindromes.
Similarly for the string
"hihellolookhavealookatthispa...
The Code used
#include<stdio.h>
struct st
{
char a;
short c;
int b;
};
struct st s1;
int main()
{
printf("%p %p \n",(&s1.b)-1, &s1);
}
If I print the address of &s1.b it prints 0x804a01c and &s1.b-2 prints 0x804a018
why it is printing same address 0x804a01c if i select &s1.b-1 ?
...
I'm a beginning programmer reading K&R, and I feel as if the book assumes a lot of previous knowledge. One aspect that confuses me is the actual representation, or should I say existence, of variables in memory. What exactly does a data type specify for a variable? I'm not too sure of how to word this question... but I'll ask a few quest...
Is it possible to have one application simultaneously write to multiple syslog facilities?
I have an application, written in C/C++, that I would like to write some messages to local0 and other messages to local1. I do not want the messages for local0 to appear in local1 or vice versa.
...
Hello,
I want self-education purpose implement a simple virtual machine for a dynamic language, prefer in C language. Something like the Lua VM, or Parrot, or Python VM, but simpler. Are there any good resources/tutorials on achieving this, apart from looking at code and design documentations of the existing VMs?
Thanks in advance for ...
Hi,
Is it true that a pointer assigned to the starting address of a dynamically allocated array does not have the information of the size of the array? So we have to use another variable to store its size for later processing the array through the pointer.
But when we free the dynamically allocated array, we don't specify the size, ins...